1
I know this has been asked multiple times… but I can’t seem to find a solution.
我知道这个问题已经被问过很多次了… … 但是我似乎找不到解决办法。
Taken from this official guidelines example: https://openjfx.io/openjfx-docs/#gradle I went on and added in my build.gradle :
从这个官方指导方针的例子中可以看出: 我继续在我的建筑中添加了一些 https://openjfx.io/openjfx-docs/#gradle :
代码语言:javascript复制plugins {
id ‘application’
id ‘org.openjfx.javafxplugin’ version ‘0.0.8’
}
javafx {
version = ‘13’
modules = [‘javafx.controls’]
}
repositories {
mavenCentral()
}
mainClassName = “MyImage”
jar {
manifest {
attributes “Main-Class”: “$mainClassName”
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
which, by running gradle jar (or gradle build), should actually produce a jar which should include all the packages it builds it with, that is the entire javafx library.
通过运行 gradle jar (或 gradle build) ,实际上应该生成一个 jar,其中应该包含所有构建它的包,即整个 javafx 库。
However, when it builds successfully and then I proceed with running:
然而,当它构建成功后,我继续跑步:
java -jar build/libs/MyImage.jar
Java-jar build/libs/MyImage.jar
it still throws the error:
它仍然会抛出错误:
Error: JavaFX runtime components are missing, and are required to run this application
错误: JavaFX 运行时组件丢失,并且需要运行此应用程序
What am I missing?
我错过了什么?
(I use JDK 11)
(我使用 JDK 11)
3
In Java 11 the Java launcher detects that you’re extending javafx.application.Application and checks the modules are present. If you’re using plain old JARs then you’ll get the error
在 java11中,Java 启动器检测到您正在扩展 javafx.application。应用程序和检查模块是否存在。如果您使用的是普通的旧罐子,那么您将得到错误
Error: JavaFX runtime components are missing, and are required to run this application You have two choices. Setup your application to use the Java module system or the following workaround.
您有两个选择。将应用程序设置为使用 Java 模块系统或下列变通方法。
This workaround avoids the Java launcher check and will let the application run.
这个解决方案避免了 Java 启动器检查,并且允许应用程序运行。
public class MyImage { // <=== note - does not extend Application
代码语言:javascript复制public static class YourRealApplication extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
// whatever...
}
}
public static void main(String[] args) {
Application.launch(YourRealApplication.class);
}
}