使用 Native sbt Packager 为 windows 打包 Play 应用程序
Posted
技术标签:
【中文标题】使用 Native sbt Packager 为 windows 打包 Play 应用程序【英文标题】:Packaging Play application for windows using Native sbt Packager 【发布时间】:2015-09-17 00:13:53 【问题描述】:我已经制作了一个小型 HTTP 服务器。我现在想构建一个带有安装的 Windows 版本。几个月前我已经做了一个,但我修改了我的应用程序,所以我必须重新安装。但是,如果不更改 sbt 文件中的所有内容,它就会失败......
这里是我用于构建安装的命令:
activator windows:packageBin
这是我在安装后启动应用程序时遇到的错误:
Oops, cannot start the server.
Configuration error: Configuration error[application: application.conf: java.io.IOException: resource not found on classpath: application.conf, application.json: java.io.IOException: resource not found on classpath: application.json, application.properties: java.io.IOException: resource not found on classpath: application.properties]
at play.api.Configuration$.play$api$Configuration$$configError(Configuration.scala:94)
at play.api.Configuration$.load(Configuration.scala:66)
at play.api.WithDefaultConfiguration$$anonfun$initialConfiguration$1.apply(Application.scala:76)
at play.api.WithDefaultConfiguration$$anonfun$initialConfiguration$1.apply(Application.scala:76)
at play.utils.Threads$.withContextClassLoader(Threads.scala:21)
at play.api.WithDefaultConfiguration$class.initialConfiguration(Application.scala:75)
at play.api.DefaultApplication.initialConfiguration$lzycompute(Application.scala:402)
at play.api.DefaultApplication.initialConfiguration(Application.scala:402)
at play.api.WithDefaultGlobal$class.play$api$WithDefaultGlobal$$globalClass(Application.scala:25)
at play.api.DefaultApplication.play$api$WithDefaultGlobal$$globalClass$lzycompute(Application.scala:402)
at play.api.DefaultApplication.play$api$WithDefaultGlobal$$globalClass(Application.scala:402)
at play.api.WithDefaultGlobal$class.play$api$WithDefaultGlobal$$javaGlobal(Application.scala:31)
at play.api.DefaultApplication.play$api$WithDefaultGlobal$$javaGlobal$lzycompute(Application.scala:402)
at play.api.DefaultApplication.play$api$WithDefaultGlobal$$javaGlobal(Application.scala:402)
at play.api.WithDefaultGlobal$$anonfun$play$api$WithDefaultGlobal$$globalInstance$1.apply(Application.scala:54)
at play.api.WithDefaultGlobal$$anonfun$play$api$WithDefaultGlobal$$globalInstance$1.apply(Application.scala:53)
at play.utils.Threads$.withContextClassLoader(Threads.scala:21)
at play.api.WithDefaultGlobal$class.play$api$WithDefaultGlobal$$globalInstance(Application.scala:52)
at play.api.DefaultApplication.play$api$WithDefaultGlobal$$globalInstance$lzycompute(Application.scala:402)
at play.api.DefaultApplication.play$api$WithDefaultGlobal$$globalInstance(Application.scala:402)
at play.api.WithDefaultGlobal$class.global(Application.scala:68)
at play.api.DefaultApplication.global(Application.scala:402)
at play.api.WithDefaultConfiguration$class.play$api$WithDefaultConfiguration$$fullConfiguration(Application.scala:82)
at play.api.DefaultApplication.play$api$WithDefaultConfiguration$$fullConfiguration$lzycompute(Application.scala:402)
at play.api.DefaultApplication.play$api$WithDefaultConfiguration$$fullConfiguration(Application.scala:402)
at play.api.WithDefaultConfiguration$class.configuration(Application.scala:84)
at play.api.DefaultApplication.configuration(Application.scala:402)
at play.api.Application$class.$init$(Application.scala:274)
at play.api.DefaultApplication.<init>(Application.scala:406)
at play.core.StaticApplication.<init>(ApplicationProvider.scala:53)
at play.core.server.NettyServer$.createServer(NettyServer.scala:253)
at play.core.server.NettyServer$$anonfun$main$3.apply(NettyServer.scala:289)
at play.core.server.NettyServer$$anonfun$main$3.apply(NettyServer.scala:284)
at scala.Option.map(Option.scala:145)
at play.core.server.NettyServer$.main(NettyServer.scala:284)
at play.core.server.NettyServer.main(NettyServer.scala)
Caused by: com.typesafe.config.ConfigException$IO: application: application.conf: java.io.IOException: resource not found on classpath: application.conf, application.json: java.io.IOException: resource not found on classpath: application.json, application.properties: java.io.IOException: resource not found on classpath: application.properties
at com.typesafe.config.impl.SimpleIncluder.fromBasename(SimpleIncluder.java:235)
at com.typesafe.config.impl.ConfigImpl.parseResourcesAnySyntax(ConfigImpl.java:128)
at com.typesafe.config.ConfigFactory.parseResourcesAnySyntax(ConfigFactory.java:811)
at com.typesafe.config.ConfigFactory.load(ConfigFactory.java:113)
at com.typesafe.config.ConfigFactory.load(ConfigFactory.java:136)
at com.typesafe.config.ConfigFactory.loadDefaultConfig(ConfigFactory.java:228)
at com.typesafe.config.ConfigFactory.access$000(ConfigFactory.java:38)
at com.typesafe.config.ConfigFactory$1.call(ConfigFactory.java:378)
at com.typesafe.config.ConfigFactory$1.call(ConfigFactory.java:375)
at com.typesafe.config.impl.ConfigImpl$LoaderCache.getOrElseUpdate(ConfigImpl.java:58)
at com.typesafe.config.impl.ConfigImpl.computeCachedConfig(ConfigImpl.java:86)
at com.typesafe.config.ConfigFactory.load(ConfigFactory.java:375)
at com.typesafe.config.ConfigFactory.load(ConfigFactory.java:299)
at play.api.Configuration$.dontAllowMissingConfig$lzycompute(Configuration.scala:29)
at play.api.Configuration$.dontAllowMissingConfig(Configuration.scala:29)
at play.api.Configuration$.load(Configuration.scala:64)
... 34 more
Caused by: com.typesafe.config.ConfigException$IO: application.conf: java.io.IOException: resource not found on classpath: application.conf
at com.typesafe.config.impl.Parseable.parseValue(Parseable.java:183)
at com.typesafe.config.impl.Parseable.parseValue(Parseable.java:170)
at com.typesafe.config.impl.Parseable.parse(Parseable.java:148)
at com.typesafe.config.impl.SimpleIncluder.fromBasename(SimpleIncluder.java:185)
... 49 more
Caused by: java.io.IOException: resource not found on classpath: application.conf
at com.typesafe.config.impl.Parseable$ParseableResources.rawParseValue(Parseable.java:579)
at com.typesafe.config.impl.Parseable$ParseableResources.rawParseValue(Parseable.java:554)
at com.typesafe.config.impl.Parseable.parseValue(Parseable.java:176)
... 52 more
这里是我的 sbt 文件:
name := """IDTabDriver"""
name in Windows := "IdTabDriver"
packageSummary in Windows := "IdTabDriver"
packageDescription in Windows := "IdTabDriver"
maintainer in Windows := "My Company"
organization := "My Company"
version := "1.0.0.1"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
scalaVersion := "2.11.1"
libraryDependencies ++= Seq(
cache,
javaWs,
"commons-configuration" % "commons-configuration" % "1.10",
"org.rxtx" % "rxtxcomm" % "2.0-7pre1"
)
如果有人有想法,我已经尝试了很多我找不到解决方案
【问题讨论】:
在您构建它或运行它时(安装后)是否会发生这种情况?你用的是哪个版本的play? (本地启动是用play run
还是activator run
?)
它发生在运行时,所以在安装后运行时。我从生成的 idtabdriver.bat 文件开始。当我在我的开发环境(在 intelliji 中)运行它时,它运行良好。我正在使用 Play 2.3
你能检查服务器和本地机器上的java版本吗?
我在自己的机器上运行这个应用程序。但是我有 2 个版本的 java(用于开发目的),我可以知道谁在使用哪个版本?
【参考方案1】:
如果您只是使用 Play 附带的功能,那么您只需在 SBT 控制台中运行 dist
。
然后在target/universal
中查找压缩文件。解压后,运行bin
文件夹中的.bat
文件。
【讨论】:
【参考方案2】:我也遇到了同样的错误,抱怨在类路径中找不到资源 application.conf。这可能与 sbt-play 插件中的 know bug 有关。在recent bug fix 发布之前,尝试将以下行添加到您的build.sbt 作为suggested by the Play development team 的解决方法。
PlayKeys.externalizeResources := false
这对我有用。
【讨论】:
以上是关于使用 Native sbt Packager 为 windows 打包 Play 应用程序的主要内容,如果未能解决你的问题,请参考以下文章
为使用 sbt-native-packager 创建的可执行文件设置 JVM 选项的推荐方法是啥?
使用 sbt native packager 为 scala play app 创建 rpm
如何使用 sbt-native-packager 创建基本项目设置
在 SBT 中为 sbt-native-packager 的 packageMappings 构建路径