Cannot find jfxrt.jar (javafx) at runtime


I am currently using just one class from javafx.util package : Pair, because I did not want to implement my own Pair class, so I thought this would be a reasonnable solution. However, I am working with Intellij, which seems to know where to find the jfxrt.jar, so I did not notice that this could cause problems.

In fact, when I run my main from Intellij, all is right, but when I try to package the application with Maven, and then java -jar myapp.jar, the application needs the Pair class, and apparently doesn't find it :

Exception in thread "main" java.lang.NoClassDefFoundError: javafx/util/Pair

So I searched around, and here is what I can tell you :

  • My JDK is 1.7.0_40, so I know jfxrt.jar is bundled, and I found it.
  • Maven version : 3.1.0
  • I am on windows seven
  • I tried to add %JAVA_HOME%\lib\ to my PATH variable, did not change anything
  • I tried to add this system dependency in my pom.xml :


But it does not seem to change anything, and even if it sound silly, I tried to copy/paste jfxrt.jar, in a lib folder within my jar, and surprisingly, it did not work either...

  • I use the maven-assembly-plugin like this :

                        <id>make-assembly</id> <!-- this is used for inheritance merges -->
                        <phase>package</phase> <!-- bind to the packaging phase -->

Should you have any suggestion, please go ahead (might be another solution for my Pair problem that does not rely on javafx ...)

3/15/2014 5:46:20 PM

How are you packaging your application? You could try with maven-assembly-plugin for packaging, there is a descriptor called jar-with-dependencies which adds them to the final artifact, you then call mvn package.

4/16/2014 1:56:32 PM

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