gpt4 book ai didi

scala - 如何在多项目中使用 Play 框架?

转载 作者:行者123 更新时间:2023-12-04 08:30:23 28 4
gpt4 key购买 nike

我正在努力寻找有关如何在根项目是普通 SBT 的多项目中使用 Play 框架的任何信息。基本上这是我的项目布局:

/
- 常见的
- 其他项目
- 我的游戏项目
- - 应用程序
- - - Controller
- - 配置文件
- - - 路线
- build.sbt

我可以通过运行 my-play-project/run 来启动应用程序在 SBT 控制台中,但是当我尝试访问任何页面时,我收到 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)

有什么明显我遗漏的东西会破坏这个项目吗? Controller 以最简单的方式定义,如文档中所述。我提供的唯一路线也是如此:
# 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

最佳答案

更新:

现在您已经发布了 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)

关于scala - 如何在多项目中使用 Play 框架?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36337175/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com