https://github.com/jasongoodwin/play21-multimodule-demo有代码 . 我've recreated this problem on 3 different projects. I don'知道怎么了 . 一旦你将aggregate和dependsOn放在build.scala文件中,项目在尝试开始播放时就会抛出错误 .
[info]从/Users/jgoodwin/.sbt/plugins [info]加载全局插件从/ Users / jgoodwin / Development / src / ninjakeyboard / test / tmp / play21-multimodule-demo / project [error] java加载项目定义.lang.ExceptionInInitializerError [error]使用'last'作为完整日志 . 项目加载失败:(r)etry,(q)uit,(l)ast,或(i)gnore? q
构建文件
import sbt._ import Keys._ import play.Project._ object ApplicationBuild extends Build {val appName =“multimodule-demo”val appVersion =“1.0-SNAPSHOT”// val scalaVersion =“2.10.0”val appDependencies = Seq (//在这里添加项目依赖项,jdbc,anorm)val buildSettings =(scalaVersion:=“2.10.0”)val main = play.Project(appName,appVersion,appDependencies,path = file(“web”)) . settings (//在这里添加你自己的项目设置).aggregate(testmodule).dependsOn(testmodule)val testmodule = Project(“testmodule”,file(“testmodlue”),settings = buildSettings)}
2 回答
我在你的github build.scala中注意到,在主模块之后声明(并初始化)了testmodule,因此在项目加载期间是null异常 . 我犯了同样的错误,按正确的顺序放置模块使其工作 . 我刚刚开始玩Play2和Scala,但我相信懒惰的val的使用也会有所帮助 .
尝试创建一个新项目:
运行命令:
play new MyApp
运行
play clean eclipse
制作dir
modules
(在MyApp内部)运行命令
play new MyModule
运行命令
play clean eclipse
将控制器重命名为MyModuleCon,并更改routes文件
运行命令
play clean publish-local
添加到MyApp Build.scala依赖项:
"mymodule" % "mymodule_2.10" % "1.0-SNAPSHOT"
将主路由重命名为app.routes(因为模块也有路由,但可以删除!)
在主项目运行中:
play dependencies eclipse
瞧,你有你的子模块,请看我的github:https://github.com/adis-me/PlayModuleExample
只需运行
play run
并访问主项目:http://localhost:9000
然后访问子模块:http://localhost:9000/module
.我认为这应该可以帮到你!
EDIT: 2013-03-27
将上述配置更改为实际的子项目设置,请按照下列步骤操作:
在MyApp上运行:
play clean
更改MyApp的Build.scala文件:
object ApplicationBuild extends Build {
运行命令:
play clean eclipse
运行命令:
play run
就是这样,你不能访问上面提到的相同网址 . 可能是您的想法无法识别子项目中的类,只需将MyModule项目作为主项目的引用库引用,您就可以了 .
祝好运!