我在嘗試部署JavaFX應用程序時遇到了一些麻煩。爲了簡化我的問題,我試圖對「Hello word」應用程序做同樣的事情,問題是一樣的。無法執行未捆綁JRE的JavaFX應用程序
我目前使用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解釋:
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.
:
...
javafx {
mainClass 'Main'
javaRuntime '<NO RUNTIME>'
}
但當gradle jfxDeploy
事實上,運行gradle jfxDeploy -i
表現出一些有趣的信息沒有束產生
好了,所以也許插件有一些錯誤我嘗試用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=
(這是相同的命令附加-Bruntime=
在this link解釋)。
該包已生成。現在它的大小約爲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中運行java 1.8.0_74,javac 1.8.0_74和javapackager 8.0 .2
你試過升級到JDK的當前版本? – FibreFoX
我剛剛升級了我的JDK版本。問題仍然存在 – Pelocho