Trying to run executable jar of JavaFX app - Error: JavaFX runtime components are missing
Trying to run executable jar of JavaFX app - Error: JavaFX runtime components are missing
我已经创建了一个可以部署的 JavaFX 11 应用程序。
我使用 Gradle 5.0 作为我的构建工具和这个命令来编译 jar:
jar {
manifest {
attributes(
'Main-Class': 'checkmydigitalfootprint.MainApp'
)
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
然后在命令行上,我尝试了对 运行 jar 文件的不同命令:
java -jar CheckMyDigitalFootprint.jar
java -jar CheckMyDigitalFootprint.jar --module-path="/users/joseph/eclipse-workspace/javafx-sdk-11.0.1/lib" --add-modules=javafx.controls
java -jar CheckMyDigitalFootprint.jar --module-path="/users/joseph/eclipse-workspace/javafx-sdk-11.0.1/lib" --add-modules=javafx.controls --add-exports=javafx.graphics/com.sun.javafx.util=ALL-UNNAMED --add-exports=javafx.base/com.sun.javafx.reflect=ALL-UNNAMED --add-exports=javafx.base/com.sun.javafx.beans=ALL-UNNAMED --add-exports=javafx.graphics/com.sun.glass.utils=ALL-UNNAMED --add-exports=javafx.graphics/com.sun.javafx.tk=ALL-UNNAMED
但都导致相同的错误:
Error: JavaFX runtime components are missing, and are required to run this application
build.gradle 的其余部分:
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.5'
id 'eclipse'
}
repositories {
mavenCentral()
}
dependencies {
/* uncomment for cross-platform jar: */
// compile "org.openjfx:javafx-graphics:11:win"
// compile "org.openjfx:javafx-graphics:11:linux"
compile "org.openjfx:javafx-graphics:11:mac"
compile 'com.jfoenix:jfoenix:9.0.8'
compile 'org.json:json:20180813'
compile 'com.google.api-client:google-api-client:1.23.0'
compile 'com.google.oauth-client:google-oauth-client-jetty:1.23.0'
compile 'com.google.apis:google-api-services-gmail:v1-rev83-1.23.0'
compile group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '2.3.1'
compile 'com.sun.activation:javax.activation:1.2.0'
compile group: 'com.sun.mail', name: 'javax.mail', version: '1.6.2'
testCompile "org.testfx:testfx-core:4.0.15-alpha"
testCompile "org.testfx:testfx-junit:4.0.15-alpha"
}
javafx {
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
run {
if (osdetector.os == 'windows') {
// Temporal fix for Eclipse with JDK 1.8 and Windows
systemProperty "java.library.path", "C:\tmp"
}
}
jar {
manifest {
attributes(
'Main-Class': 'checkmydigitalfootprint.MainApp'
)
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
mainClassName = 'checkmydigitalfootprint.MainApp'
上有解释
解决方法很简单,只需添加以下VM选项:
--module-path /path/to/javafx-sdk-11.0.1/lib --add-modules=javafx.controls,javafx.fxml
为您的 Gradle 项目应用 JavaFX gradle 插件
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.5'
}
添加所需的模块。例如:
javafx {
modules = [ 'javafx.controls' ]
}
指定 JavaFX 版本
javafx {
version = "11.0.+"
}
希望这对您有所帮助:)
我没有使用 Gradle 的经验,但在使用提供 "JavaFX runtime components are missing..." 的可运行 jar 时遇到了同样的问题。 (使用 openJDK/JFX 11.)即使 vm 参数已正确包含在命令行中。问题是用于构建可运行 jar 的 "Library handling" 选项。 "Extract required libraries.." 没有完成任务。 "Package required libraries..." 是构建具有 JavaFX 依赖项的可运行 jar 文件的正确选项。
你用这个解决了问题
Java -jar --module-path /path/to/javafx-sdk-11.0.1/lib --add-modules=javafx.controls,javafx.fxml (路径你的 jar 文件)
我已经创建了一个可以部署的 JavaFX 11 应用程序。
我使用 Gradle 5.0 作为我的构建工具和这个命令来编译 jar:
jar {
manifest {
attributes(
'Main-Class': 'checkmydigitalfootprint.MainApp'
)
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
然后在命令行上,我尝试了对 运行 jar 文件的不同命令:
java -jar CheckMyDigitalFootprint.jar
java -jar CheckMyDigitalFootprint.jar --module-path="/users/joseph/eclipse-workspace/javafx-sdk-11.0.1/lib" --add-modules=javafx.controls
java -jar CheckMyDigitalFootprint.jar --module-path="/users/joseph/eclipse-workspace/javafx-sdk-11.0.1/lib" --add-modules=javafx.controls --add-exports=javafx.graphics/com.sun.javafx.util=ALL-UNNAMED --add-exports=javafx.base/com.sun.javafx.reflect=ALL-UNNAMED --add-exports=javafx.base/com.sun.javafx.beans=ALL-UNNAMED --add-exports=javafx.graphics/com.sun.glass.utils=ALL-UNNAMED --add-exports=javafx.graphics/com.sun.javafx.tk=ALL-UNNAMED
但都导致相同的错误:
Error: JavaFX runtime components are missing, and are required to run this application
build.gradle 的其余部分:
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.5'
id 'eclipse'
}
repositories {
mavenCentral()
}
dependencies {
/* uncomment for cross-platform jar: */
// compile "org.openjfx:javafx-graphics:11:win"
// compile "org.openjfx:javafx-graphics:11:linux"
compile "org.openjfx:javafx-graphics:11:mac"
compile 'com.jfoenix:jfoenix:9.0.8'
compile 'org.json:json:20180813'
compile 'com.google.api-client:google-api-client:1.23.0'
compile 'com.google.oauth-client:google-oauth-client-jetty:1.23.0'
compile 'com.google.apis:google-api-services-gmail:v1-rev83-1.23.0'
compile group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '2.3.1'
compile 'com.sun.activation:javax.activation:1.2.0'
compile group: 'com.sun.mail', name: 'javax.mail', version: '1.6.2'
testCompile "org.testfx:testfx-core:4.0.15-alpha"
testCompile "org.testfx:testfx-junit:4.0.15-alpha"
}
javafx {
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
run {
if (osdetector.os == 'windows') {
// Temporal fix for Eclipse with JDK 1.8 and Windows
systemProperty "java.library.path", "C:\tmp"
}
}
jar {
manifest {
attributes(
'Main-Class': 'checkmydigitalfootprint.MainApp'
)
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
mainClassName = 'checkmydigitalfootprint.MainApp'
解决方法很简单,只需添加以下VM选项:
--module-path /path/to/javafx-sdk-11.0.1/lib --add-modules=javafx.controls,javafx.fxml
为您的 Gradle 项目应用 JavaFX gradle 插件
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.5'
}
添加所需的模块。例如:
javafx {
modules = [ 'javafx.controls' ]
}
指定 JavaFX 版本
javafx {
version = "11.0.+"
}
希望这对您有所帮助:)
我没有使用 Gradle 的经验,但在使用提供 "JavaFX runtime components are missing..." 的可运行 jar 时遇到了同样的问题。 (使用 openJDK/JFX 11.)即使 vm 参数已正确包含在命令行中。问题是用于构建可运行 jar 的 "Library handling" 选项。 "Extract required libraries.." 没有完成任务。 "Package required libraries..." 是构建具有 JavaFX 依赖项的可运行 jar 文件的正确选项。
你用这个解决了问题
Java -jar --module-path /path/to/javafx-sdk-11.0.1/lib --add-modules=javafx.controls,javafx.fxml (路径你的 jar 文件)