2

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

Thibault
  • 568
  • 3
  • 10
  • 21
  • 2
    Writing that class would have been quicker than writing this question and doing all the research. Why exactly don't you want to put [these few lines](http://grepcode.com/file/repo1.maven.org/maven2/net.java.openjfx.backport/openjfx-78-backport/1.8.0-ea-b96.1/javafx/util/Pair.java) somewhere in your code? – zapl Mar 15 '14 at 17:43
  • Because I wanted to do it in a "cleaner" way that copy/pasting code. Afterall, why is maven there if we cannot use dependencies? But thanks anyway, I will do that until I have another solution – Thibault Mar 15 '14 at 17:49
  • possible duplicate of [Maven project with JavaFX (with jar file in \`lib\`)](http://stackoverflow.com/questions/15278215/maven-project-with-javafx-with-jar-file-in-lib) – jewelsea Mar 15 '14 at 17:52
  • I would not even consider that a cleaner way if that's the only thing you use from a library. Reason somewhere along those lines: http://en.wikipedia.org/wiki/Package_principles – zapl Mar 15 '14 at 17:58

2 Answers2

0

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.

tshepang
  • 12,111
  • 21
  • 91
  • 136
-1

jfxrt.jar is not in lib folder ...

It is in lib/ext/

e.g., jdk1.8.0_211/jre/lib/ext/jfxrt.jar

thedrs
  • 1,412
  • 12
  • 29