How to create a Play 2.2 Scala application as an SBT sub-project

后端 未结 2 995
梦如初夏
梦如初夏 2020-12-29 23:07

I am trying to create a Scala application consisting of a library project (let\'s call this common), a Thrift server project (let\'s call this server

相关标签:
2条回答
  • 2020-12-29 23:45

    if

     play (entering shell)
     project web
     run
    

    works, then you can make it work from the command line:

     play "project web" "run"
    

    You can do in command line whatever you can do in the shell.

    I have the same project structure and it is the way to do that works fine for me.

    By the way, I don't think the hot reload stuff is related to Play. It is incremental compilation that is provided by SBT which is used by Play. The play command is just some hacked SBT launcher I think.

    The following command works fine for me:

     sbt "project web" "run"
    

    And it starts the Play project with hot reload.


    I think you can even use

     sbt "project web" "~run"
    

    Which will try to recompile each time you change a source file, instead of waiting for a browser refresh, and will make win some time.

    0 讨论(0)
  • 2020-12-30 00:02

    I think this is a bug in Play 2.2, so I reported it as Error "/:playRunHooks is undefined" on running as web/run. Also it seems to have been fixed in 2.3.x, so likely it won't be fixed for 2.2. Here's a bit nerdy workaround I came up with:

    lazy val root = (project in file(".")).
      settings(
        playRunHooks := Nil,
        playInteractionMode := play.PlayConsoleInteractionMode,
        playDefaultPort := 9000,
        playMonitoredFiles := (Def.taskDyn {
          val s = state.value
          s.history.current.split("/").headOption match {
            case Some(ref) =>
              Def.task {
                (playMonitoredFiles in LocalProject(ref)).value
              }
            case _ =>
              Def.task {
                playMonitoredFiles.value
              }
          } 
        }).value
      )
    
    0 讨论(0)
提交回复
热议问题