【发布时间】:2016-02-12 13:23:32
【问题描述】:
我在尝试部署 JavaFX 应用程序时遇到了一些麻烦。为了简化我的问题,我尝试对“Hello word”应用程序做同样的事情,但问题是一样的。
我目前正在使用 IntelliJ IDEA 和 Gradle。
我的build.gradle 文件是这样的:
apply plugin: 'java'
apply from: "http://dl.bintray.com/content/shemnon/javafx-gradle/8.1.1/javafx.plugin"
repositories {
mavenCentral()
}
javafx {
mainClass 'Main'
}
build.gradle 文件有效。问题在于它将 JRE 嵌入到包中,因此文件大小约为 175 MB。这对于一个简单的“Hello World”应用来说太过分了,你不觉得吗?
所以,我想在没有 JRE 的情况下捆绑这个简单的应用程序(是的,我知道我应该分发我的应用程序并捆绑了 JRE,这样它就不会中继使用系统,但我将分发两个版本:并且没有捆绑 JRE)。为此,我在build.gradle 文件中添加了一行(如this link 中所述:
...
javafx {
mainClass 'Main'
javaRuntime '<NO RUNTIME>'
}
但gradle jfxDeploy 时不会生成任何捆绑包。事实上,运行gradle jfxDeploy -i 会显示一些有趣的信息:
Java runtime to be bundled: none, bundle will rely on locally installed runtimes
...
Skipping Mac Application Image because of configuration error The file for the Runtime/JRE directory does not exist.
Advice to Fix: Point the runtime parameter to a directory that containes the JRE.
Skipping DMG Installer because of configuration error The file for the Runtime/JRE directory does not exist.
Advice to Fix: Point the runtime parameter to a directory that containes the JRE.
Skipping PKG Installer because of configuration error The file for the Runtime/JRE directory does not exist.
Advice to Fix: Point the runtime parameter to a directory that containes the JRE.
Skipping Mac App Store Ready Bundler because of configuration error The file for the Runtime/JRE directory does not exist.
Advice to Fix: Point the runtime parameter to a directory that containes the JRE.
好的,所以也许插件有一些错误。我尝试使用javapackager 生成捆绑包。我转到项目文件夹并运行以下命令:
javapackager -deploy -native image -srcfiles build/libs/ -outdir build/distributions -outfile Sample -appclass Main
输出正常。该捆绑包是使用嵌入的 JRE 正确生成的。现在我尝试用这个生成一个没有 JRE 的包:
javapackager -deploy -native image -srcfiles build/libs/ -outdir build/distributions -outfile Sample -appclass Main -Bruntime=
(与this link 中解释的附加-Bruntime= 的命令相同。
包已生成。现在它的大小约为 500 KB。但是当我尝试运行它时,什么也没有发生。在终端中运行它会得到以下(简化的)输出:
$ Main.app/Contents/MacOS/Main
Failed to find library.:
Main:Failed to locate JNI_CreateJavaVM
Main:Failed to launch JVM
似乎捆绑包无法启动本地 JVM。 jar 已正确生成并添加到包中。使用java -jar 运行它会运行应用程序,但我不知道为什么它在运行捆绑包时不起作用
仅供参考,我在 OS X 10.11.2 中运行 java 1.8.0_74、javac 1.8.0_74 和 javapackager 8.0
【问题讨论】:
-
您是否尝试过升级到当前版本的JDK?
-
我刚刚升级了我的 JDK 版本。问题依然存在
标签: macos intellij-idea gradle javafx-8