我正在尝试使用 SBT 部署多模块 Play项目。
我们的项目有5个模块[commons, channel , ...]
。
当我在本地系统中使用sbt run
时,一切正常。
要在服务器中部署,我使用sbt dist
到build the project。
但是当我使用由sbt dist
生成的脚本运行我的应用程序时,会出现问题!
以下是错误的一个示例:
[error] error_handler - Unhandled Error
java.lang.IllegalArgumentException: No query defined for that name [automaticChannel.getTagByChannelId]
at org.hibernate.internal.AbstractSharedSessionContract.buildQueryFromName(AbstractSharedSessionContract.java:770)
at org.hibernate.internal.AbstractSharedSessionContract.createNamedQuery(AbstractSharedSessionContract.java:748)
at org.hibernate.internal.AbstractSessionImpl.createNamedQuery(AbstractSessionImpl.java:23)
at repositories.GenericRepository.namedQuery(GenericRepository.java:291)
at repositories.GenericRepository.namedNativeQuery(GenericRepository.java:573)
at repositories.AutomaticChannelRepository.getTagIds(AutomaticChannelRepository.java:63)
at services.AutomaticChannelService.lambda$tagIds$6(AutomaticChannelService.java:159)
at play.db.jpa.DefaultJPAApi.lambda$withTransaction$3(DefaultJPAApi.java:197)
at play.db.jpa.DefaultJPAApi.withTransaction(DefaultJPAApi.java:138)
at play.db.jpa.DefaultJPAApi.withTransaction(DefaultJPAApi.java:196)
GenericRepository 类存在于 commons 模块中, AutomaticChannelRepository 存在于 channel 模块中。
buid.sbt
档案的一部分:
lazy val connector = (project in file("modules/connector"))
.enablePlugins(PlayScala)
.settings(
commonSettings,
libraryDependencies += "org.mindrot" % "jbcrypt" % "0.4"
)
lazy val common = (project in file("modules/common"))
.enablePlugins(PlayJava)
.dependsOn(connector)
.settings(
commonSettings,
libraryDependencies ++= Seq(
javaJdbc,
filters,
guice,
javaWs,
ehcache,
javaJpa,
evolutions,
"org.hibernate" % "hibernate-entitymanager" % "5.2.11.Final",
"org.hibernate" % "hibernate-ehcache" % "5.2.11.Final",
"org.hibernate.javax.persistence" % "hibernate-jpa-2.1-api" % "1.0.0.Final",
"com.google.code.gson" % "gson" % "2.1",
"com.oracle" % "ojdbc8" % "12.2.0.1",
"commons-io" % "commons-io" % "2.4",
"commons-lang" % "commons-lang" % "2.6",
"org.apache.commons" % "commons-collections4" % "4.1",
"org.hibernate" % "hibernate-core" % "5.2.10.Final",
"org.apache.tika" % "tika-core" % "1.13",
"org.apache.tika" % "tika-parsers" % "1.13" exclude("com.google.code.gson", "gson"),
"org.apache.tika" % "tika-xmp" % "1.13",
"org.jsoup" % "jsoup" % "1.10.1",
"com.thoughtworks.xstream" % "xstream" % "1.3"
)
)
lazy val search = (project in file("modules/search")).enablePlugins(PlayJava).dependsOn(common).settings(commonSettings)
lazy val channel = (project in file("modules/channel")).enablePlugins(PlayJava).dependsOn(common, search).settings(commonSettings)
lazy val recommend = (project in file("modules/recommend")).enablePlugins(PlayJava).dependsOn(common, search).settings(commonSettings)
lazy val root = (project in file("."))
.enablePlugins(PlayJava)
.dependsOn(channel, recommend)
.aggregate(channel, recommend)
.settings(commonSettings)
我想知道sbt run
和sbt dist
之间有什么区别?
部署多模块SBT项目的常见和推荐方法是什么?
答案 0 :(得分:0)
这是一个类路径问题。您必须在build.sbt中添加以下代码:
PlayKeys.externalizeResources := false
默认情况下,项目中的资源未打包在sbt dist
创建的jar文件中。