How can I get javafx classes into runtime?


I am willing to try javafx for the first time, I went to Oracle javafx site to find that javafx now comes with the JDK 7u25. I updated my java version but I am not sure what I am looking for. I get "cannot find symbol" errors whenever I try to import and use a javafx class. I found "javafx-mx.jar" "javafx-doclet.jar" "ant-javafx.jar" files in %JAVA_HOME%/lib but as far as I understand, those are meant to be used by the JRE not the JDK. I would really like not to be dependant on any eclipse plugins. I use maven for the build process. I have seen a couple of javafx maven plugins, but they seem to target the javafx tools. Am I getting the wrong picture? How would I get those classes to be imported correctly?


Now I am able to compile the project using what I found here. It suggest to add:


This solved my build issues, but I can't run the program, I am trying to run this simple example, but I get this error:

java.lang.NoClassDefFoundError: javafx/application/Application
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(
    at Method)
    at java.lang.ClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
    at org.codehaus.mojo.exec.ExecJavaMojo$
Caused by: java.lang.ClassNotFoundException: javafx.application.Application
    at Method)
    at java.lang.ClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(

Any ideas on how to add the same library to runtime? I am using maven-exec-plugin.

7/18/2013 11:03:08 PM

Accepted Answer

Just making jfxrt.jar a maven system dependency is not recommended

I don't think integrating maven with your JavaFX build via a system dependency to jfxrt.jar is a good idea.

Using that method you will be able to build your application (because the system dependency for the javafx runtime classes will allow maven to find them).

But when you go to run your application with Java 7, you will still need to manually add the classpath to your java.exe command, similar to Compile code using JavaFX 2.0 (using command line).

I don't use the maven exec plugin, but see add a jar to maven exec:java classpath, which provides instructions on setting the appropriate classpath for that exec plugin, if you want to use the tool in this way.

Preferred approach

The preferred approach is to properly package your application using a recommended deployment tool (e.g. JavaFX ant tasks, javafxpackager, javafx-maven-plugin or javafx-gradle-plugin).

These tools will embed a small wrapper main class in your application jar which will find the JavaFX runtime if it is available or help guide users through a runtime install if it is not.

Also, if you use Oracle Java 8, javafx will be on your default classpath so you won't need to worry about classpath related issues.

5/23/2017 12:15:14 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow