13

我正在尝试将我的 Play!Framework 2.2 项目拆分为子项目,但我很难弄清楚。

这是我的文件夹结构:

MyProject/
 | - app/
 | --- controllers/ # containing some main controllers
 | --- views/ # resulting views
 | - build.sbt # see after
 | - conf/
 | --- application.conf
 | --- routes
 | --- modules/ # My modules folder, aka sub projects
 | -------- common/
 | ------------ app/
 | --------------- models/ # The models
 | --------------- utils/
 | -------- api/
 | -------- web/
 | ------------ app/ # some controllers/views
 | ------------ conf/ # routes mainly
 | ------------ app/ # some controllers/views
 | ------------ conf/ # routes mainly

(我简化了它)。

routes文件:

# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~

# Home page
GET     /                             controllers.StaticPages.index()

# Web
->  /html/v1 web.Routes

# API
->  /api/v1  api.Routes

web.routes :

# HTML Engine renderer
# ~~~~~~~~~~~~~~~~~~~~

GET   /users                controllers.Users.list()

api.routes:

# API
# ~~~~~~~~~~~~~~~~~~~~

GET   /users                controllers.Users.list()

最后,我的build.sbt

import play.Project._

name := "My project"

version := "1.0-alpha"

libraryDependencies ++= Seq(
  javaJdbc,
  javaEbean,
  cache,
  "mysql" % "mysql-connector-java" % "5.1.25",
  "com.typesafe" %% "play-plugins-mailer" % "2.2.0"
)

play.Project.playJavaSettings

lazy val root = project.in(file("."))
    .dependsOn(common, web, api)
    .aggregate(common, web, api)

lazy val web = project.in(file("modules/web"))
    .dependsOn(common)

lazy val api = project.in(file("modules/api"))
    .dependsOn(common)

lazy val common = project.in(file("modules/common"))

清理/编译和运行时,我遇到了这个错误:

未找到:值 web 在第 20 行的 /path/to/project/conf/routes 中。-> /html/v1 web.Routes

如果我删除->routes文件中的,播放!找不到共同的软件包实用程序。

所以我猜很常见,web 和 api 没有加载,但为什么呢?

更新

由于@James-roper 帮助我找到了问题,我创建了一个 Github 存储库,其中显示了一个简单的 Play!Framework 2.2 项目和子项目。你可以在这里找到它:https ://github.com/cnicodeme/play2.2-subproject

4

1 回答 1

11

您的子项目需要使用不同的包名称,此时它们发生冲突。

于 2013-10-18T01:00:08.190 回答