英文:
Showing error " JavaFX runtime components are missing, and are required to run this application" while running jar file in command prompt
问题
我在IntelliJ中创建了一个项目,并从中构建了一个jar文件(指定了主类)。但是当我尝试使用命令提示符运行jar文件时,出现以下错误:缺少JavaFX运行时组件,需要这些组件来运行此应用程序(在命令提示符中)。我该如何解决这个问题?(我对此不太了解。请尽量简单地解释。)
命令提示符命令:java -jar 文件名.jar
最终,我想要的是通过单击一个图标来运行我的JavaFX应用程序。我该如何做到这一点?是否有其他方法可以运行我的应用程序,就像运行其他应用程序一样,只需单击一个图标即可?我不想每次都打开IntelliJ来运行我的应用程序。
我使用了:
操作系统:Windows 10 | IntelliJ IDEA 2020.2.3 | jdk 14.0.2 | jre 1.8.0_251 | javaFX 15
(顺便说一下,我将JavaFX 15安装在另一个驱动器上,而不是包含操作系统的同一硬盘驱动器上)
英文:
I created a project in IntelliJ and built a jar file from it (the main class is specified). But when I tried to run the jar file using cmd I am getting this error: JavaFX runtime components are missing, and are required to run this application(in command prompt). How can I fix this issue? (I am new to this. Please try to explain as easy as possible.)
cmd command: java -jar filename.jar
In the end, what I want is to run my JavaFX application just by clicking a single icon. How can I do that??? Are there any other ways to run my application like any other application run, just by clicking one icon? I don't want to open IntelliJ every time to run my application.
I used:
OS: Windows 10 | IntelliJ IDEA 2020.2.3 | jdk 14.0.2 | jre 1.8.0_251 | javaFX 15
(By the way, I installed JavaFX 15 in another drive. Not in the same hard drive which contains OS)
答案1
得分: 3
你可以尝试这样做:
在项目上右键单击,然后选择导出,之后选择导出为可运行的JAR文件,不要忘记选择第二个选项,你需要将它与已使用的库一起导出,这样应该可以通过命令行运行您的JAR文件,并尝试加载所有模块,而不仅仅是javafx.controls。
--module-path "在这里放置路径" --add-modules=ALL-MODULE-PATH
或者
您可以执行以下步骤,这可能有所帮助
文件 >> 项目结构 >> 模块 >> 依赖项 >> +(位于窗口左侧)
单击“+”符号以指定您解压缩JavaFX的“lib”文件夹的目录。然后:
运行 >> 编辑配置
为了修复这个错误,尝试加载所有模块
--module-path "在这里放置路径" --add-modules=javafx.controls,javafx.fxml
英文:
you can try this:
right click on your project then select export after that select export as runnable jar file don't forget to select second choice you have to export it with used lib, this should be able to run your jar using cmd
and try to load all modules, not just javafx.controls
--module-path "put_here_the_path" --add-modules=ALL-MODULE-PATH
Or
You can do this step it can help
File >> Project Structure >> Modules >> Dependency >> + (on left-side of window)
click the "+" sign to designate the directory where you have unpacked JavaFX's "lib" folder.
then:
Run >> Edit Configurations
to fix this error try to load all modules
--module-path "put_here_the_path" --add-modules=javafx.controls,javafx.fxml
答案2
得分: 1
你想要实现的目标可以通过JDK 14引入的jpackage工具来完成。
在这里查看:https://github.com/dlemmermann/JPackageScriptFX
英文:
What you want to achieve can be done via the jpackage tool introduced in JDK 14.
Have a look here: https://github.com/dlemmermann/JPackageScriptFX
答案3
得分: 1
因为您正在使用IntelliJ IDEA,所以按照以下说明操作:
-
转到Run → Edit Configurations
-
转到VM Options并添加这些参数:
--module-path "C:\Fx\javafx-sdk-11.0.2\lib"
--add-modules javafx.controls,javafx.fxml,javafx.base,javafx.web
--add-exports javafx.graphics/com.sun.javafx.sg.prism=ALL-UNNAMED
只需知道,对于我的情况,我创建了文件夹并将JAR文件存储在那个目录中。至于那部分内容,您需要进行修改,其余的就是历史。您只需将路径更改为存储JavaFX JAR文件的位置。
英文:
Since you are using IntelliJ-IDEA, then you follow these instructions.
-
Go to Run → Edit Configurations
-
Go to VM Options and add these arguments:
>
--module-path "C:\Fx\javafx-sdk-11.0.2\lib"
>--add-modules javafx.controls,javafx.fxml,javafx.base,javafx.web
>--add-exports javafx.graphics/com.sun.javafx.sg.prism=ALL-UNNAMED
Just know that, for mine, I created the folder and stored the JAR files in that directory. For that part, you modify it and the rest is history. You just need to change the directory of the path to where you store your JavaFX JAR Files.
答案4
得分: 0
我已将-Djava.library.path=C:/go-out-of-my-way-eclipse 添加到运行时参数。我不记得我在哪里找到过这个建议。
英文:
I have added -Djava.library.path=C:/go-out-of-my-way-eclipse to the runtime arguments. I don't remember where I had found this advice.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论