gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 11:13:54 25 4
gpt4 key购买 nike

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

最佳答案

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

我通过添加 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目录下的文件添加到主项目classpath中

关于java - Play Framework 2.3.4 路由重定向到子项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26179557/

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