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 :
<dependencies> <dependency> <groupId>javafx</groupId> <artifactId>jfxrt</artifactId> <version>2.0</version> <scope>system</scope> <systemPath>${java.home}/lib/jfxrt.jar</systemPath> </dependency> </dependencies>
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 :
<groupId>minmax</groupId> <artifactId>minmax</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>javafx</groupId> <artifactId>jfxrt</artifactId> <version>2.0</version> <scope>system</scope> <systemPath>${java.home}/lib/jfxrt.jar</systemPath> </dependency> </dependencies> <build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <archive> <manifest> <mainClass>fr.tlasnier.jeux.puissance4.ihm.Puissance4Main</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> <executions> <execution> <id>make-assembly</id> <!-- this is used for inheritance merges --> <phase>package</phase> <!-- bind to the packaging phase --> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
Should you have any suggestion, please go ahead (might be another solution for my Pair problem that does not rely on javafx ...)