如何在多项目中使用Play Framework?

时间:2016-03-31 15:05:26

标签: scala playframework sbt playframework-2.5

我正在努力寻找有关如何在多项目中使用Play Framework的任何信息,其中根项目是一个简单的SBT项目。基本上这是我项目的布局:

/
- 共同的 - 其他一些项目
- 我的游戏项目
- - app
- - - 控制器
- - conf
- - - 路线
- build.sbt

我可以通过在SBT控制台中运行my-play-project/run来启动应用程序,但是当我尝试访问任何页面时,我得到500并记录此错误:

[error] /someorg/backend/cms/conf/routes: package router does not exist
[error] /someorg/backend/cms/conf/routes: cannot find symbol
[error]   symbol:   class ReversePostController
[error]   location: package controllers
[error] /someorg/backend/cms/conf/routes: package controllers.javascript does not exist
[error] /someorg/backend/cms/conf/routes: cannot find symbol
[error]   symbol:   class ReversePostController
[error]   location: package controllers
[error] /someorg/backend/cms/conf/routes: cannot find symbol
[error]   symbol:   variable RoutesPrefix
[error]   location: class controllers.routes
[error] /someorg/backend/cms/conf/routes: package controllers.javascript does not exist
[error] /someorg/backend/cms/conf/routes: cannot find symbol
[error]   symbol:   variable RoutesPrefix
[error]   location: class controllers.routes.javascript
[error] (cms/compile:compileIncremental) javac returned nonzero exit code
[info] Compiling 6 Scala sources and 1 Java source to /someorg/backend/cms/target/classes...
[error] /someorg/backend/cms/conf/routes: package router does not exist
[error] /someorg/backend/cms/conf/routes: cannot find symbol
[error]   symbol:   class ReversePostController
[error]   location: package controllers
[error] /someorg/backend/cms/conf/routes: package controllers.javascript does not exist
[error] /someorg/backend/cms/conf/routes: cannot find symbol
[error]   symbol:   class ReversePostController
[error]   location: package controllers
[error] /someorg/backend/cms/conf/routes: cannot find symbol
[error]   symbol:   variable RoutesPrefix
[error]   location: class controllers.routes
[error] /someorg/backend/cms/conf/routes: package controllers.javascript does not exist
[error] /someorg/backend/cms/conf/routes: cannot find symbol
[error]   symbol:   variable RoutesPrefix
[error]   location: class controllers.routes.javascript
[error] (cms/compile:compileIncremental) javac returned nonzero exit code
[error] application -

! @6pi9jna82 - Internal server error, for (GET) [/posts] ->

play.sbt.PlayExceptions$CompilationException: Compilation error[package router does not exist]
    at play.sbt.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27)
    at play.sbt.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27)
    at scala.Option.map(Option.scala:145)
    at play.sbt.run.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:49)
    at play.sbt.run.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:44)
    at scala.Option.map(Option.scala:145)
    at play.sbt.run.PlayReload$.taskFailureHandler(PlayReload.scala:44)
    at play.sbt.run.PlayReload$.compileFailure(PlayReload.scala:40)
    at play.sbt.run.PlayReload$$anonfun$compile$1.apply(PlayReload.scala:17)
    at play.sbt.run.PlayReload$$anonfun$compile$1.apply(PlayReload.scala:17)

有什么明显的我遗漏了打破这个项目吗?控制器的定义方式最简单,如文档中所述。我提供的唯一路线也是如此:

# Route
GET       /posts        controllers.PostController.list

// Controller
package controllers

import play.api.mvc.{Action, Controller}

class PostController extends Controller {
  def list = TODO
}

我正在使用Play Framework 2.5.1,项目构建定义如下:

lazy val resolvers = ...

lazy val projectSettings = Seq(
  organization := "some-organization",
  scalaBinaryVersion := "2.11",
  scalaVersion := "2.11.7",
  externalResolvers := resolvers,
  moduleConfigurations := Seq(),
  retrieveManaged := true,
  concurrentRestrictions in Global += Tags.limit(Tags.Test, 1),
  transitiveClassifiers in Scope.GlobalScope := Seq("sources"),
  ivyLoggingLevel := UpdateLogging.Quiet,
  credentials += Credentials(Path.userHome / ".ivy2" / ".credentials"),
  crossPaths := false,
  publishMavenStyle := true,
  publishArtifact in (Compile, packageDoc) := false,
  publishArtifact in (Test, packageDoc) := false,
  javacOptions := Seq("-source", "1.8", "-target", "1.8", "-encoding", "utf8"),
  javaOptions := Seq("-server", "-XX:ReservedCodeCacheSize=192m", "-Xss2m"),
  javaOptions in Test := Seq("-server", "-Xmx2g", "-XX:ReservedCodeCacheSize=192m", "-Xss2m"),
  testFrameworks := Seq(TestFrameworks.ScalaTest, TestFrameworks.Specs2),
  noTestCompletion(),
  scalacOptions := Seq(
    "-deprecation",
    "-optimize",
    "-unchecked",
    "-encoding", "utf8",
    "-target:jvm-1.8",
    "-Xlog-reflective-calls",
    "-feature",
    "-language:_"
  ) ++ Seq(
      "by-name-right-associative",
      "delayedinit-select",
      "doc-detached",
      "inaccessible",
      "missing-interpolator",
      "nullary-override",
      "option-implicit",
      "package-object-classes",
      "poly-implicit-overload",
      "private-shadow",
      "unsound-match"
    ).map(x => s"-Xlint:$x"),
  compileOrder := CompileOrder.JavaThenScala,
  fork in Test := true,
  testOptions in Test := Seq(Tests.Filter(testName => testName.endsWith("Test") || testName.endsWith("Spec"))),
  testOptions in Test += Tests.Argument("-oDF"),
  testOptions in Test <+= (target in Test).map { t =>
    val testDir = t / "test-reports"
    val maybeJUnitXml = if (flag("sbt.test.nojunitxml")) Seq.empty else Seq("-u", testDir.getAbsolutePath)
    Tests.Argument(TestFrameworks.ScalaTest, maybeJUnitXml: _*)
  }
)

lazy val cms = (project in file("cms"))
  .settings(projectSettings)
  .dependsOn(common, commonTest % "test", model % compileTest)
  .enablePlugins(PlayScala)

lazy val root = (project in file("."))
  .settings(projectSettings)
  .aggregate(common, some-other-projects, cms) // TODO: Remove web

2 个答案:

答案 0 :(得分:3)

更新:

既然您已经发布了build.sbt文件,我认为问题在于编译顺序。 javac失败,因为找不到提到的包。

尝试使用默认的Mixed编译顺序。

我怀疑您没有在my-play-project子项目中启用sbt-play插件,因此您的路由文件未编译为my-play-project/target/scala-2.11/routes/main/router

my-play-project/build.sbt中,添加:

enablePlugins(PlayScala)

答案 1 :(得分:0)

尝试将Play插件声明添加到/project/plugins.sbt的根项目中