如何在Play框架中创建子项目? (play#play-java_2.9.2; 2.1-RC3:找不到) [英] How to create sub projects in Play Framework? (play#play-java_2.9.2;2.1-RC3: not found)
问题描述
我想测试子项目的工作方式,尤其是在主项目中如何考虑子项目的routes
(
I want to test how sub projects work, especially how the routes
of the sub project are taken into account in main project (this was not visible before).
我在这里阅读了文档: https://github.com/playframework/Play20/wiki/SBTSubProjects
I have read the docs here: https://github.com/playframework/Play20/wiki/SBTSubProjects
我做了什么:(下载play 2.1 RC3之后)
What have I done: (after downloading play 2.1 RC3)
- 创建新的Java项目:
play new MainProject
- 在MainProject中创建新文件夹:
modules
- 创建新的Java项目:
play new SubProject
- Create new Java Project:
play new MainProject
- Create new folder inside MainProject:
modules
- Create new Java Project:
play new SubProject
在两个项目上:play eclipse
因为play eclipsify
不再起作用
On both projects: play eclipse
since play eclipsify
does not work anymore
在主项目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)
}
现在,在主项目中运行:
Now, in the main project I run:
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
,但是我一直收到此错误.
Note
I have tried to delete the Build.scala
from the subproject but I kep getting this error.
我在做什么错了?
推荐答案
最终使其正常工作:
- 您不必从子项目中删除
Build.scala
.
您需要重命名子项目的路由文件.在我的示例中,为subProject.routes
.如果要单独运行子项目,则需要声明路由必须解析为subProject.routes.因此,将其添加到子项目的application.conf
中:
You need to rename the routes file of your sub project. In my example, to subProject.routes
. If you want to run your subproject in isolation you need to declare that routes must resolve to your subProject.routes. So add this in the application.conf
of your subProject:
application.router=subProject.Routes
在您的主项目中,您需要从子项目中导入路线:
In your main project, you need to import the routes from the subproject:
-> /subProject subProject.Routes
主项目的构建文件应类似于:示例来自SCALA,但s
And the build file of the main project should look something like: example is from SCALA but s
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)
}
这篇关于如何在Play框架中创建子项目? (play#play-java_2.9.2; 2.1-RC3:找不到)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!