0

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

J3fro C
  • 9
  • 1
  • 1
    You can use `jlink` to build a JRE with the JavaFX runtime already embedded. If you do that, you can use that runtime to execute your jar file without those options. You can go one step further, and build a native application bundle (exe, msi, dmg, pkg, rpm, depending on the OS and your preferences) embedding that JRE and your jar file. The `jpackage` tool included in JDK14 can be used to perform both steps (it actually calls `jlink`) in a single command. – James_D Sep 05 '20 at 21:20
  • check graalvm and gluonhq too https://github.com/gluonhq/client-samples – ozkanpakdil Sep 07 '20 at 17:17
  • Look at https://openjfx.io/openjfx-docs/ under Runtime Images or JavaFX and Eclipse. – user1803551 Sep 07 '20 at 19:06

0 Answers0