【问题标题】:Unable to execute a JavaFX application bundled without JRE无法执行没有 JRE 捆绑的 JavaFX 应用程序
【发布时间】: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


【解决方案1】:

来自 shemnon 的 javafx.plugin 不再开发或维护,因此我创建了 javafx-gradle-plugin

问题来自.cfg-file-format 的内部更改,他们现在使用 INI 文件,但这在 RUNTIME 配置方面存在缺陷。

我报告的官方 JDK-bug-tickets:
(jdk 9)https://bugs.openjdk.java.net/browse/JDK-8143314

(jdk 8) https://bugs.openjdk.java.net/browse/JDK-8143934

在您的构建中将一些捆绑器参数 launcher-cfg-format 设置为 cfg 就足够了(或使用 javafx-gradle-plugin,它自动包含该解决方法)。

免责声明:我是 javafx-maven-plugin 的维护者,也是 javafx-gradle-plugin 的创建者和维护者。

更新 此问题已得到修复并在 JDK 8u92 中可用

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-28
相关资源
最近更新 更多