I made a program to calculate "Attestation de vacances", it's not important what it is, but i coded it on IntelliJ idea with use of javafx. Everything works perfectly in intelliJ but when i build it into a .jar file it doesn't work. Why? I'm searching whole day for sollution and i did everything i found on the internet. Right now i'm trying to run it on cmd console but i'm getting this error "Error: JavaFX runtime components are missing, and are required to run this application.". Once again... I was looking for it on the internet and i've tried multiple methods to repair this so i'm assuming that everything with it is okay and this errer pops up just because yes, and the program doesn't work because no. So once again i ask, how tf do i run .jar file? Isn't it a double click? Maybe it's triple click then? Or a toe click or i dunno...
我做了一个计算“假期证明”的程序,它是什么并不重要,但我用JavaFX在IntelliJ IDEA上编写了它。在IntelliJ中,一切都运行得很好,但当我将其构建到.jar文件中时,它就不起作用了。为什么?我一整天都在寻找解决方案,我在网上找到的每一件事我都做了。现在,我正试图在cmd控制台上运行它,但收到了这个错误“Error:缺少运行此应用程序所需的JavaFX运行时组件。”再一次。我一直在互联网上寻找它,我尝试了多种方法来修复它,所以我假设它一切正常,这个错误弹出,只是因为是,程序不起作用,因为不是。所以我再问一次,我该如何运行.jar文件?这不是双击吗?也许这就是三次点击?或者脚趾咔哒声或者我不知道..。
更多回答
Well you could use maven shade, which is unsupported. Or you could use the javafx maven plugin to jlink the app. Further instructions are in the runtime image section of the getting started instructions at openjfx.io. There are also hundreds of questions on this on this site.
你可以使用maven shade,这是不支持的。或者你也可以使用javafx maven插件来jlink这个应用,更多的说明在openjfx.io的入门指南的运行时图片部分。这个网站上也有数百个关于这个问题的问题。
Note that error typically means your main class is a subclass of javafx.application.Application
but the javafx.graphics
module was not found in the boot module layer. JavaFX only technically supports being loaded as named modules. That, for a few reasons, means that executable JAR files are not really supported for JavaFX applications, especially if you're trying to create a so-called fat/uber/shaded JAR file. It's possible to have an executable JAR file, but that basically means having a JDK/JRE (which could have been created via jlink
) that includes JavaFX in the run-time image.
请注意,错误通常意味着您的主类是javafx.Applation.Application的子类,但在引导模块层中没有找到该javafx.graph模块。从技术上讲,JavaFX只支持作为命名模块加载。出于几个原因,这意味着JavaFX应用程序并不真正支持可执行的JAR文件,尤其是当您试图创建一个所谓的FAT/UBER/Shaded JAR文件时。可以有一个可执行的JAR文件,但这基本上意味着要有一个在运行时映像中包含JavaFX的JDK/JRE(可以通过jlink创建)。
There are quite a few links under the "Packaging" section of the JavaFX tag info page if you want some deployment ideas. Also check out openjfx.io/openjfx-docs
如果您需要一些部署方面的想法,在JavaFX标签信息页面的“打包”部分有相当多的链接。还可以查看Openjfx.io/Openjfx-docs
优秀答案推荐
Can you share a some of the code you are using?
你能分享一些你正在使用的代码吗?
You'll need to make sure to specify the main class (usually META-INF/MANIFEST.MF), specify the main class for your application. The manifest should contain a line like this:
您需要确保指定主类(通常为META-INF/MANIFEST.MF),并为您的应用程序指定主类。清单应包含如下一行:
Main-Class: com.yourpackage.YourMainClass
You'll also want to run the JAR file with JavaFX
您还需要使用JavaFX运行JAR文件
java --module-path /path/to/javafx-sdk/lib --add-modules javafx.controls,javafx.fxml -jar YourApp.jar
/path/to/javafx-sdk/lib
should point to the lib directory of your JavaFX SDK installation.
/PATH/to/JavaFX-SDK/lib应该指向您的JavaFX SDK安装的lib目录。
更多回答
I did, my manifest has line "Main-Class: org.example.Main", it's correct main class because i don't have any other, and for the javafx my program works when i don't use VM Options with "java --module-path /path/to/javafx-sdk/lib --add-modules javafx.controls,javafx.fxml -jar YourApp.jar" but when i try to apply it, then my program stops working in intelliJ idea aswell. But thanks for trying to help!
我做了,我的清单有行“Main-Class:org.example.Main”,这是正确的Main类,因为我没有任何其他的Main类,并且对于JavaFX,当我没有使用带有“Java--模块-路径/路径/to/JavaFX-SDK/lib--添加模块javafx.Controls,javafx.fxml-jar YourApp.jar”的VM选项时,我的程序也停止在IntelliJ IDEA中工作。不过,还是要谢谢你的帮忙!
And even if i run jar file with javafx it's still not working
即使我用JavaFX运行JAR文件,它仍然不起作用
Hmm – then it might the Project Language Level doesn't match the Java Version –– or the project compiler isn't pointing to the correct output directory for compiled classed, or the Project SDK needs to be set differently.
嗯-那么可能是项目语言级别与Java版本不匹配--或者项目编译器没有指向正确的已编译Classed的输出目录,或者Project SDK需要进行不同的设置。
我是一名优秀的程序员,十分优秀!