如何在Play Framework中创建子项目? (播放#play-java_2.9.2; 2.1-RC3:未找到)

时间:2013-01-29 15:53:25

标签: playframework-2.0 playframework-2.1

我想测试子项目的工作原理,特别是如何在主项目(this was not visible before)中考虑子项目的routes

我在这里阅读了文档: https://github.com/playframework/Play20/wiki/SBTSubProjects

我做了什么:(下载播放2.1 RC3后)

  1. 创建新的Java项目:play new MainProject
  2. 在MainProject中创建新文件夹:modules
  3. 创建新的Java项目:play new SubProject
  4. 在两个项目中:play eclipse,因为play eclipsify不再有效

    在主要项目Build.scala文件中:

    import sbt._
    import Keys._
    import play.Project._
    
    object ApplicationBuild extends Build {
    
      val appName         = "MainProject"
      val appVersion      = "1.0-SNAPSHOT"
    
      val appDependencies = Seq(
        // Add your project dependencies here,
        javaCore,
        javaJdbc,
        javaEbean 
      )
    
      val subProject = Project("subproject", file("modules/SubProject"))
    
      val main = play.Project(appName, appVersion, appDependencies).settings(
        // Add your own project settings here      
      ).dependsOn(subProject)
    
    }
    

    现在,在我运行的主项目中:

    play run
    

    我收到以下错误:

    [error] (MainProject/*:update) sbt.ResolveException: unresolved dependency: play#play_2.9.2;2.1-RC3: not found
    [error] unresolved dependency: play#play-java_2.9.2;2.1-RC3: not found
    [error] unresolved dependency: play#play-java-jdbc_2.9.2;2.1-RC3: not found
    [error] unresolved dependency: play#play-java-ebean_2.9.2;2.1-RC3: not found
    [error] unresolved dependency: play#play-test_2.9.2;2.1-RC3: not found
    

    注意的 我试图从子项目中删除Build.scala,但我得到了这个错误。

    我做错了什么?

2 个答案:

答案 0 :(得分:12)

终于搞定了:

  • 您不必从子项目中删除Build.scala

您需要重命名子项目的路线文件。在我的例子中,subProject.routes。如果要单独运行子项目,则需要声明路由必须解析为subProject.routes。因此,请在子项目的application.conf中添加:

application.router=subProject.Routes

在主项目中,您需要从子项目中导入路线:

->  /subProject               subProject.Routes

主项目的构建文件应该类似于:示例来自SCALA,但是

import sbt._
import Keys._
import play.Project._

object ApplicationBuild extends Build {

  val appName         = "MainProject"
  val appVersion      = "1.0-SNAPSHOT"

  val appDependencies = Seq(
    // Add your project dependencies here,
   javaCore,
   javaJdbc,
   javaEbean 
  )

  val subProject = play.Project(
    appName + "-subProject", appVersion, path = file("modules/SubProject")
  )

  val main = play.Project(appName, appVersion, appDependencies).settings(
    // Add your own project settings here      
  ).dependsOn(subProject)

}

答案 1 :(得分:0)

我发现我必须将scala版本显式设置为2.10.0,因为子项目与2.9.2发生冲突。

val main = play.Project(appName, appVersion, appDependencies).settings(
    scalaVersion := "2.10.0"
)

取自this question

的示例