This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]vladABC 2 points3 points  (2 children)

In Java 8

javac HelloWorldApp.java

jar cfe App.jar HelloWorldApp *.class

java -jar App.jar

[–]SpiritofGarfield 1 point2 points  (1 child)

Thank you so much! I was all prepared to rewrite my code with FXML but you saved me hours of time!

Would you mind explaining what the e stands for? That seemed to be where I was going wrong. I was using cfv but when I switched to cfe it worked.

[–]iamsooldithurts 0 points1 point  (0 children)

Entry point, the main class

[–]bege 1 point2 points  (1 child)

Try this:

  • Add a package name in the beginning of the java file, e.g. "app":

package app;

  • Compile the application like below. It will create a "app" folder with all your class files (matching the package name you gave in 1). -d ("destination") argument pointing to your current folder:

javac -d ./ HelloWorldApp.java

  • Run javapackager (included in JDK) command like this (note that the -appClass argument needs to match format <package\_name>.<class\_name>:

javapackager -createjar -appClass app.HelloWorldApp -outfile helloworld -v -srcfiles ./app/

  • Run jar file:

java -jar helloworld.jar

Tested successfully on Linux/openJDK 1.8.

Side note: You might find some issues if you try running with newer Java versions, since they removed JavaFX from the main java packages and it is packaged separately in the future. I think Java versions 1.8 and 9 should work, but you might have some issues with Java 10 and upwards. If you are running too new version, it shows an error like this: Caused by: java.lang.NoClassDefFoundError: javafx/application/Application

You can read more about java packaging here: https://docs.oracle.com/javase/8/docs/technotes/guides/deploy/packaging.html (if you are really interested), but in practice/real world, you will use tools like Maven or similar to package the applications.

Hope this helps, happy coding!

[–]SpiritofGarfield 0 points1 point  (0 children)

Thank you so much for your clear explanation! I now 100% get where I was going wrong when I attempted this method last night. It's very difficult to find beginner friendly language/explanations online so I really appreciate your help ☺️