Play Framework 2.3.4将重定向路由到子项目

时间:2014-10-03 13:09:23

标签: java playframework routes playframework-2.3 subproject

使用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最后一行的子变量。如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

我有同样的问题(虽然项目结构与所有示例和文档中的相同,路线文件位于正确的位置) - 子项目路线文件尚未被放入主目标/ scala-2.11 / routes并且无法找到

我在build.sbt:

的末尾添加unmanagedResourceDirectories in Compile += baseDirectory.value / "<path_to_project>/conf解决了这个问题
....
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目录下添加文件以包含在主项目类路径中

答案 1 :(得分:0)

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