Reputation: 59
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)
Upvotes: 4
Views: 21597
Reputation: 544
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.
Upvotes: 2
Reputation: 118
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
Upvotes: 3
Reputation: 10642
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
Upvotes: 1
Reputation: 2217
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.
Upvotes: 0