Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

NoClassDefFoundError: javafx/application/Application

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?
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/1686...fx-applica

he includes some extra packaging/dependencies in the maven shit in one answer
[Image: wKo4TU0.gif]
(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/1686...fx-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.
(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.
(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 :)


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Java] by OBAMASELFFeb 8, 2019 03:13 AM 2 204 Feb 8, 2019 03:13 AM
Last Post: OBAMASELF
[Java] by Consulting DetectiveAug 29, 2018 04:54 PM 4 264 Aug 29, 2018 04:54 PM
Last Post: +Haze
[Java] by +HazeJun 9, 2017 12:47 AM 61 8,273 Jun 9, 2017 12:47 AM
Last Post: +Haze