简体   繁体   中英

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 :

     <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 ...)

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.

jfxrt.jar is not in lib folder ...

It is in lib/ext/

eg, jdk1.8.0_211/jre/lib/ext/jfxrt.jar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM