如何将 sbt 与 Google App Engine 结合使用?

发布于 2024-08-02 08:34:22 字数 70 浏览 7 评论 0原文

有人尝试过设置 sbt 来与 Google App Engine 一起使用吗?我梦想在源代码更改后使用开发服务器自动重新加载。

Has anybody tried to setup sbt to work with Google App Engine? I dream about using development server auto-reloading after source changes.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

说不完的你爱 2024-08-09 08:34:22

如需快速演示,您可以在此处克隆或下载我所做的工作。

从头开始的简约sbt-appengine-plugin示例

克隆 sbt-appengine-来自 GitHub 的插件

 cd mystuff
 git clone git://github.com/Yasushi/sbt-appengine-plugin.git
 cd sbt-appengine-plugin
 sbt

在本地发布插件,以便您可以在自己的项目中使用它

publish-local
exit

为新项目创建目录

cd ..
mkdir sbt-appengine-plugin-test
cd sbt-appengine-plugin-test
sbt

配置新项目< /strong>

Project does not exist, create new project? (y/N/s) y
Name: sbt-appengine-plugin-test
Organization: com.example
Version [1.0]: 
Scala version [2.7.7]: 2.8.0.Beta1
sbt version [0.7.3]:
exit

告诉 sbt 你想要使用的插件

mkdir project/build
mkdir project/plugins
nano project/build/project.scala

project.scala

import sbt._

class AppengineTestProject(info: ProjectInfo) extends AppengineProject(info)

nano project/plugins/plugins.scala

plugins.scala

import sbt._

class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
  val a = "net.stbbs.yasushi" % "sbt-appengine-plugin" % "1.1-SNAPSHOT"
}

添加一个非常简单的 servlet >

mkdir -p src/main/scala/com/example
nano -w src/main/scala/com/example/HelloWorld.scala

HelloWorld.scala

package com.example;

import javax.servlet.http.{HttpServlet, HttpServletRequest, HttpServletResponse}

class HelloWorld extends HttpServlet {
  override def doGet(request: HttpServletRequest, response: HttpServletResponse$
    response.setContentType("text/plain")
    response.getWriter.println("Hello, world")
  }
}

添加更多配置文件

mkdir -p src/main/webapp/WEB-INF
nano -w src/main/WEB-INF/web.xml

web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app 
   xmlns="http://java.sun.com/xml/ns/javaee" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xm$
   version="2.5">
  <display-name>sbt-appengine-plugin usage example</display-name>
      <servlet>
    <servlet-name>helloworld</servlet-name>
    <servlet-class>com.example.HelloWorld</servlet-class>
  </servlet>
      <servlet-mapping>
    <servlet-name>helloworld</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>


nano -w src/main/WEB-INF/appengine-web.xml

appengine-web.xml

<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<!-- Replace this with your application id from http://appengine.google.com -$
  <application>hello-world</application>
  <version>1</version>
</appengine-web-app>

最后运行 sbt 并启动项目

sbt

update
dev-appserver-start

将浏览器指向 http://localhost:8080/ 并你应该看到 Hello, world

dev-appserver-stop

为了观察源文件的变化,我在启动服务器后用 ~prepare-webapp 做了一些实验,但我还没有让它正常工作。

For a quick demo you can clone or download what I have done here.

A minimalistic sbt-appengine-plugin example from scratch

Clone the sbt-appengine-plugin from GitHub

 cd mystuff
 git clone git://github.com/Yasushi/sbt-appengine-plugin.git
 cd sbt-appengine-plugin
 sbt

Publish the plugin locally so that you can use it in your own projects

publish-local
exit

Create a directory for a new project

cd ..
mkdir sbt-appengine-plugin-test
cd sbt-appengine-plugin-test
sbt

Configure the new project

Project does not exist, create new project? (y/N/s) y
Name: sbt-appengine-plugin-test
Organization: com.example
Version [1.0]: 
Scala version [2.7.7]: 2.8.0.Beta1
sbt version [0.7.3]:
exit

Tell sbt about the plugin you want to use

mkdir project/build
mkdir project/plugins
nano project/build/project.scala

project.scala

import sbt._

class AppengineTestProject(info: ProjectInfo) extends AppengineProject(info)

nano project/plugins/plugins.scala

plugins.scala

import sbt._

class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
  val a = "net.stbbs.yasushi" % "sbt-appengine-plugin" % "1.1-SNAPSHOT"
}

Add a very simple servlet

mkdir -p src/main/scala/com/example
nano -w src/main/scala/com/example/HelloWorld.scala

HelloWorld.scala

package com.example;

import javax.servlet.http.{HttpServlet, HttpServletRequest, HttpServletResponse}

class HelloWorld extends HttpServlet {
  override def doGet(request: HttpServletRequest, response: HttpServletResponse$
    response.setContentType("text/plain")
    response.getWriter.println("Hello, world")
  }
}

Add some more configuration files

mkdir -p src/main/webapp/WEB-INF
nano -w src/main/WEB-INF/web.xml

web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app 
   xmlns="http://java.sun.com/xml/ns/javaee" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xm$
   version="2.5">
  <display-name>sbt-appengine-plugin usage example</display-name>
      <servlet>
    <servlet-name>helloworld</servlet-name>
    <servlet-class>com.example.HelloWorld</servlet-class>
  </servlet>
      <servlet-mapping>
    <servlet-name>helloworld</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>


nano -w src/main/WEB-INF/appengine-web.xml

appengine-web.xml

<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<!-- Replace this with your application id from http://appengine.google.com -$
  <application>hello-world</application>
  <version>1</version>
</appengine-web-app>

And finally run sbt and start the project

sbt

update
dev-appserver-start

Point your browser to http://localhost:8080/ and you should see Hello, world

dev-appserver-stop

To watch for changes in source files I have experimented a little with ~prepare-webapp after starting the server, but I haven't gotten it working properly.

余生共白头 2024-08-09 08:34:22

这是我在 Github 上的 sbt-appengine-plugin试图立即开始工作。我会发布任何进展。

Here is an sbt-appengine-plugin on Github that I'm trying to get to work right now. I will post any progress.

稀香 2024-08-09 08:34:22

您可以在这里找到该插件作者的示例:
http://gist.github.com/377611

特别是在插件配置中,1.1-的设置SNAPSHOT(上面提到的)或 2.1-SNAPSHOT(在 sbt-apppengine-plugin README 中提到的)不起作用。

这个例子表明:

import sbt._

class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
    val appenginePlugin = "net.stbbs.yasushi" % "sbt-appengine-plugin" % "2.0" from "http://github.com/downloads/Yasushi/sbt-appengine-plugin/sbt-appengine-plugin-2.0.jar"
}

这对我有用。

You will find an example by the author of the plugin here:
http://gist.github.com/377611

Especially in the plugins configuration, the setting of 1.1-SNAPSHOT (mentioned above) or 2.1-SNAPSHOT (mentioned in the sbt-apppengine-plugin README) did not work.

The example shows:

import sbt._

class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
    val appenginePlugin = "net.stbbs.yasushi" % "sbt-appengine-plugin" % "2.0" from "http://github.com/downloads/Yasushi/sbt-appengine-plugin/sbt-appengine-plugin-2.0.jar"
}

And this worked for me.

浪漫人生路 2024-08-09 08:34:22

这是一个使用 sbt + appengine 的模板项目,可用于入门:

https://github .com/mtkopone/sbt-scalatra-appengine-template

此外,您可以在 Plugins.scala 中使用以下内容,而不必在本地发布 sbt-appengine-plugin:

import sbt._
class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
  lazy val appEngine = "net.stbbs.yasushi" % "sbt-appengine-plugin" % "2.1" 
    from "http://cloud.github.com/downloads/Yasushi/sbt-appengine-plugin/sbt-appengine-plugin-2.1.jar"  
}

Here's a template project using sbt + appengine which can be used to get started:

https://github.com/mtkopone/sbt-scalatra-appengine-template

Also, instead of having to publish the sbt-appengine-plugin locally, you can use the following in Plugins.scala:

import sbt._
class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
  lazy val appEngine = "net.stbbs.yasushi" % "sbt-appengine-plugin" % "2.1" 
    from "http://cloud.github.com/downloads/Yasushi/sbt-appengine-plugin/sbt-appengine-plugin-2.1.jar"  
}
老子叫无熙 2024-08-09 08:34:22

我编写了一个示例应用程序,描述如何设置开发环境并使用 SBT 和应用程序引擎创建应用程序。它还包括有关设置 JRebel 以获得您梦想的自动重新加载的说明。

请参阅 http://jeremys-scala-example.appspot.com/

它适用于 SBT 0.7所以它有点过时了。

I wrote an example application describing how to set up a development environment and create an application using SBT and app engine. It also includes instructions on setting up JRebel to get the auto reloading you dream of.

See http://jeremys-scala-example.appspot.com/

It is for SBT 0.7 so its a little out of date.

人生百味 2024-08-09 08:34:22

现在有一个新版本的 sbt-appengine 插件,可与较新版本的 SBT (0.10+) 配合使用,网址为 https ://github.com/sbt/sbt-appenginehttps://github.com/sbt/sbt-appengine

我刚刚转换了一个使用 Eclipse 创建的项目:

  • 将 scala 文件从 src/ 移动到 src/main/scala。
  • 如果您有 java 文件,请将它们从 src/ 移动到 src/main/java。
  • 将 war/ 移动到 src/main/webapp。
  • 如果您还有其他文件应该位于 WEB-INF/classes 中,请将它们放入 src/main/webapp/WEB-INF/classes/ 中。

There is now a new version of the sbt-appengine plugin which works with newer versions of SBT (0.10+) at https://github.com/sbt/sbt-appengine. There's also a trivial sample app using it at https://github.com/sbt/sbt-appengine.

I just converted a project that was created with Eclipse:

  • Move scala files from src/ to src/main/scala.
  • If you have java files, move them from src/ to src/main/java.
  • Move war/ to src/main/webapp.
  • If you have other files that should end up in WEB-INF/classes, put them in src/main/webapp/WEB-INF/classes/.
水染的天色ゝ 2024-08-09 08:34:22

在谷歌搜索中找到了这篇文章。由于所有提供的示例都很旧,我根据我在网上找到的内容创建了两个示例项目

Found this post in Google search. Since all provided examples are quite old I created two sample projects based on what I found online

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文