【问题标题】:Using Play!Framework 2.2 subprojects使用 Play!Framework 2.2 子项目
【发布时间】:2013-10-24 13:10:23
【问题描述】:

我正在尝试将我的 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"))

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

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

如果我删除主 routes 文件中的 ->,播放!找不到通用的包 utils。

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

更新

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

【问题讨论】:

    标签: playframework-2.2


    【解决方案1】:

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

    【讨论】:

    • 我尝试了一个非常简单的子项目,它只包含一个controllers.admin.Admin.class 文件,以及到前面提到的类的index() 的路由映射,它只返回一个ok("good");。包名不同,但我还是遇到了同样的错误。
    • 在你给我的示例项目中,你没有声明管理项目和根项目之间的依赖关系。我添加了这个,它对我来说很好用:lazy val root = project.in(file(".")).aggregate(admin).dependsOn(admin) lazy val admin = project.in(file("admin" ))
    • 我更新了 github repo 以在 Play 2.2 中显示一个简单的拆分项目,供其他寻求帮助的人使用。
    • @Cyril N. 谢谢举个例子,我只有 1 个问题。使用 play 2.2.1,我创建了新的 play 项目,并在 build.sbt 中添加了与您在 github-examples 中相同的行。在播放编译并播放 Eclipse 表单命令行后,我得到关注 pokit.org/get/?557452cb165b30f7cebac1ea8a6e630a.jpg,下一步该做什么?正如我在模块中看到的这个项目不是播放项目。
    • 把它们当作游戏项目,比如在 admin/ 中添加 app/controllers、app/models、app/views、conf/,它应该可以工作。 (不要忘记每个子模块中的 build.sbt)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-01
    • 1970-01-01
    • 2014-03-01
    • 2014-06-19
    • 1970-01-01
    • 2014-03-23
    • 1970-01-01
    相关资源
    最近更新 更多