JavaFX Exception in thread “main” java.lang.NoClassDefFoundError: javafx/application/Application

I’ve worked on this very same issue for the past few hours. Even though I haven’t seen it written explicitly, it appears that you MUST use one of the JavaFX packaging tools, which is either an Ant task or the javafxpackager executable. (See http://docs.oracle.com/javafx/2/deployment/packaging.htm, section 5.3.1). The NetBeans IDE uses Ant to package the code. (I’m using IntelliJ)

When you use one of those packaging methods, in addition to all of your application’s code and resources, it also adds the following to your output JAR file:

/com/javafx/main/Main$1.class
/com/javafx/main/Main$2.class
/com/javafx/main/Main.class
/com/javafx/main/NoJavaFXFallback.class

With these in place, you can run the app from the command line:

java -jar outjar.jar

and all works fine. If I remove the extra com.javafx.main files, the app does not run.

To double-check this, I looked at all four JAR files in the JavaFX samples (BrickBreaker, Ensemble, FXML-LoginDemo, and SwingInterop). They all have the “extra” files, too.

For my small test app, I used this command line to build an “executable” JAR file:

javafxpackager -createjar -appclass sample.Main -outfile outjar -v -nocss2bin -srcdir C:\workspaces\garoup1\out\production\javafx1

Hope this helps!

Leave a Comment