Hack Forums
[Java] NoClassDefFoundError: javafx/application/Application - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Java] NoClassDefFoundError: javafx/application/Application (/showthread.php?tid=5936480)



NoClassDefFoundError: javafx/application/Application - Tenno - Feb 1, 2019

Hello,

I'm having some trouble running my jar. It works perfectly fine in Intellij IDEA, but when running it from command line I get this error:
Code
Error: Could not find or load main class com.myapp.Main
Caused by: java.lang.NoClassDefFoundError: javafx/application/Application


I have read that this might be an issue with Java 11. I'm currently running OpenJDK11. java -version returns this:
Code
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)

This is a Maven project. I have added these dependencies for JavaFX:
Code
       <dependency>
           <groupId>org.openjfx</groupId>
           <artifactId>javafx-controls</artifactId>
           <version>11.0.2</version>
       </dependency>
       <dependency>
           <groupId>org.openjfx</groupId>
           <artifactId>javafx-fxml</artifactId>
           <version>11.0.2</version>
       </dependency>
I run the command mvn clean install, and the build is successful

My VM options for Intellij are these:
Code
--module-path "C:\path\to\javafx\javafx-sdk-11.0.2\lib"  --add-modules=javafx.controls,javafx.graphics,javafx.fxml

Does anybody have any idea what might be causing this issue? Do I have to go back to Java 8 JDK?


RE: NoClassDefFoundError: javafx/application/Application - BottomNotch - Feb 2, 2019

what command u running via command line? sure the full package is getting included? this is same pc?

did u see this yet? - https://stackoverflow.com/questions/16868446/javafx-exception-in-thread-main-java-lang-noclassdeffounderror-javafx-applica

he includes some extra packaging/dependencies in the maven shit in one answer


RE: NoClassDefFoundError: javafx/application/Application - Tenno - Feb 2, 2019

(Feb 2, 2019 11:25 AM)BottomNotch Wrote:  what command u running via command line? sure the full package is getting included? this is same pc?

did u see this yet? - https://stackoverflow.com/questions/16868446/javafx-exception-in-thread-main-java-lang-noclassdeffounderror-javafx-applica

he includes some extra packaging/dependencies in the maven shit in one answer

I run java -jar myapp.jar. By full package, do you mean all dependencies? And yes, this is on the same computer.

I tried the different solutions in the link you provided, but unfortunately, it did not solve it.


RE: NoClassDefFoundError: javafx/application/Application - NeXTSTEP - Feb 3, 2019

(Feb 2, 2019 03:39 PM)Tenno Wrote:  I run java -jar myapp.jar. By full package, do you mean all dependencies? And yes, this is on the same computer.

I tried the different solutions in the link you provided, but unfortunately, it did not solve it.

Yeah so you're going to want a "fat jar" in this case (maven doesn't auto pack in your dependencies unless you tell it to). I really don't like fat jar's however, so instead I would create a tiny launch script that include
Code
java -Djavafx.whatever,etc.blah.blah -jar myapp.jar
to neatly package it all up as an executable.


RE: NoClassDefFoundError: javafx/application/Application - Tenno - Feb 3, 2019

(Feb 3, 2019 12:30 AM)NeXTSTEP Wrote:  Yeah so you're going to want a "fat jar" in this case (maven doesn't auto pack in your dependencies unless you tell it to). I really don't like fat jar's however, so instead I would create a tiny launch script that include
Code
java -Djavafx.whatever,etc.blah.blah -jar myapp.jar
to neatly package it all up as an executable.

Yeah, I got it working by using the maven-assembly-plugin and running
Code
mvn clean compile assembly:single
But I'm also not a fan of having a huge jar.

For your command to work, what do I need to give to the user? Do I need to install OpenJFX and have it in the same folder as the jar? I also have other dependencies, like JFoenix.

This is the first application I've made that is actually going to be used by people, so I'm trying to figure things out :)