JDK Version - jdk-13.0.2
JFX Version - javafx-sdk-11.0.2
Eclipse Version - 2020-03 e(fx)clipse plugin installed
OS: Windows 10
My project is a game built with just Java and purely Javafx.
I did the steps below to make my project work with Javafx:
Right-click java project > Build path > Configure build path -> Libraries tab -> Then added external jars (all javafx jar files) into Modulepath
And then gone onto:
Run -> Run Configurations -> selected the right Java application that launches my program -> Arguments tab -> pasted the code below within VM arguments section:
--module-path "C:\Program Files\Java\javafx-sdk-11.0.2\lib" --add-modules=javafx.controls,javafx.fxml
I did these steps to export to a JAR file:
Right-click my java project -> Export -> Java -> JAR File -> selected correct java project -> selected a export destination -> selected the correct Main class
When trying to see if it worked in windows command prompt, I tried the following:
C:\Users\myname\Documents\testjarfiles> java -jar minesweeper.jar
Error: Could not find or load main class controllers.startWindow
Caused by: java.lang.NoClassDefFoundError: javafx/application/Application
C:\Users\myname\Documents\testjarfiles> java -jar --module-path "path_to_the_javafx_jarfiles\javafx-sdk-11.0.2\lib" --add-modules javafx.controls,javafx.fxml minesweeper.jar
From this point on it worked and I could play my GUI game. Is there a way where I don't have to write --module-path ... and --add-modules ... just to execute my jar file?
I need this jar file to be added within my project folder as a way to let other people access and run the system, using the same way (java -jar minesweeper.jar). As they will be accessing my gitLab repo.
Note: I did search all over stackoverflow. Alot of solutions involved intelliJ, Netbeans, Maven or Gradle ... none of which I am using.
I only found out about adding the module path within the command prompt through this: Executable .jar not running JavaFX - Ecliipse