Reputation: 980
I'm using Intelij and I'm having some trouble packaging my Java app.
I'm using an Artifact to package my app. There's an option to create either a Jar package or a JavaFx package. If I use a JavaFx artifact, I'm required to specify an Application
class to start. My package uses a standard java main(String[] args)
type start up as it also has the option to be run strictly from the command line (no UI) so this option doesn't work for me.
If I instead create a jar, my main
method apparently has no idea what an Application
class is: Exception in thread "main" java.lang.NoClassDefFoundError: javafx/application/Application
What magic am I completely missing? Any bump in the right direction would be much appreciated.
Upvotes: 1
Views: 2162
Reputation: 396
If you have this exception it's because you don't have the JavaFX runtime in your classpath. In your JavaFX 2.2 installation directory, there's a folder called rt. Inside the folder, you have jfxrt.jar and some native libraries.
If you want to run your JavaFX app, the jfxrt.jar must be included in the classpath. You don't have it, that's why Java can't find the javafx.application.Application class.
For example (in windows): C:\Program Files\Oracle\JavaFX 2.2 SDK\rt C:\Program Files\Oracle\JavaFX 2.2 SDK\rt\bin*.dll C:\Program Files\Oracle\JavaFX 2.2 SDK\rt\lib\jfxrt.jar
If you use Oracle Java 8, then jfxrt.jar
will automatically be on the runtime classpath, so you don't need to manually add jfxrt.jar
to the classpath for Java 8.
Upvotes: 2