How to use sbt with Google App Engine?

后端 未结 7 1828
北海茫月
北海茫月 2021-01-31 05:08

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

相关标签:
7条回答
  • 2021-01-31 05:51

    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.

    0 讨论(0)
  • 2021-01-31 05:51

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

    • Sample GAE app written in Scala using Scalatra 2.0.5, Scala 2.10.3 and SBT 0.13 https://github.com/cppexpert/scalatra-google-app-engine-app

    • Sample GAE app written in Scala using Unfiltered 0.7, Scala 2.10.3 and SBT 0.13 https://github.com/cppexpert/sample-scala-google-app-engine-app

    0 讨论(0)
  • 2021-01-31 05:54

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

    0 讨论(0)
  • 2021-01-31 05:55

    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.

    0 讨论(0)
  • 2021-01-31 05:55

    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/.
    0 讨论(0)
  • 2021-01-31 05:58

    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.

    0 讨论(0)
提交回复
热议问题