How to use sbt with Google App Engine?

后端 未结 7 2058
北海茫月
北海茫月 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: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

    
    
      sbt-appengine-plugin usage example
          
        helloworld
        com.example.HelloWorld
      
          
        helloworld
        /
      
    
    
    
    nano -w src/main/WEB-INF/appengine-web.xml
    

    appengine-web.xml

    
    
         
     
    热议问题