2

Play 框架很新,但我尝试为我的主项目设置子项目,但是当我尝试将路由从主项目重定向到子项目时,它无法识别子项目变量。我根据PlaySubProject此处的文档进行了跟踪

我的主要项目结构如下图所示:

Main
   app
   conf
      application.conf
      routes
   modules
      sub
         app
         conf
            sub.routes
         build.sbt
   logs
   project
   public
   target
   test
   activator
   activator-launch-1.2.10.jar
   build.sbt

这是我的主要 build.sbt 文件:

name := """Main"""

version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayJava).aggregate(sub).dependsOn(sub)

lazy val sub = (project in file("modules/sub")).enablePlugins(PlayJava)

scalaVersion := "2.11.1"

libraryDependencies ++= Seq(
  javaJdbc,
  javaEbean,
  cache,
  javaWs
)

我的子项目 build.sbt 如下:

name := """Subproject"""

version := "1.0-SNAPSHOT"

scalaVersion := "2.11.1"

libraryDependencies ++= Seq(
  javaJdbc,
  javaEbean,
  cache,
  javaWs
)

最后,这是我的主要路线文件。

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

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

# Map static resources from the /public folder to the /assets URL path
GET        /assets/*file        controllers.Assets.at(path="/public", file)

# SUB's
->  /sub    sub.Routes

问题出在这个路由文件中,它甚至无法识别最后一行的子变量sub.Routes。如何解决这个问题呢?

4

2 回答 2

1

我遇到了同样的问题(尽管项目结构与所有示例中的一样,并且文档和路由文件位于正确的位置) - 子项目路由文件尚未放入主 target/scala-2.11/routes 并且不能找不到

我通过unmanagedResourceDirectories in Compile += baseDirectory.value / "<path_to_project>/conf在 build.sbt 末尾添加来解决它:

....
lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean)
  .settings(commonSettings: _*)
  .aggregate(core, providers, zms, api)
  .dependsOn(core, providers, zms, api)

lazy val core = (project in file("apps/core")).enablePlugins(PlayJava, PlayEbean)
  .settings(commonSettings: _*)
  .settings(
    name := "core"
  )

lazy val zms = (project in file("apps/zms")).enablePlugins(PlayJava, PlayEbean)
  .settings(commonSettings: _*)
  .settings(
    name := "zms"
  )
  .dependsOn(core)

lazy val api = (project in file("apps/api")).enablePlugins(PlayJava, PlayEbean)
  .settings(commonSettings: _*)
  .settings(
    name := "api"
  )
  .dependsOn(core)


//Here are the lines that solved the problem
unmanagedResourceDirectories in Compile += baseDirectory.value / "apps/core/conf"
unmanagedResourceDirectories in Compile += baseDirectory.value / "apps/zms/conf"
unmanagedResourceDirectories in Compile += baseDirectory.value / "apps/api/conf"

fork in Compile := true

它会说 sbt 在子项目 conf 目录下添加文件以包含在主项目类路径中

于 2016-07-22T11:37:18.190 回答
0

我不确定您的具体问题,但我在https://github.com/josh-padnick/play-multiproject-template设置了一个完整工作且记录合理的多项目示例。这是基于 Play 2.2.3(不是 2.3.x),但它应该非常接近您的需要。

于 2014-10-04T05:09:28.310 回答