1 Reply Latest reply: Feb 7, 2013 12:22 PM by jsmith RSS

    Why doesn't Maven find jfxrt.jar, although it is included in the JDK?

    csh
      Hi,

      Why doesn't Maven find jfxrt.jar, although it is included in the JDK?

      My solution to build JavaFX apps with Maven is:
      <dependency>
                  <groupId>com.oracle</groupId>
                  <artifactId>javafx</artifactId>
                  <version>2.2</version>
                  <scope>system</scope>
                  <systemPath>${java.home}/lib/jfxrt.jar</systemPath>
      </dependency>
      It works, but I wonder why the Maven build process can't find it automatically, as any other Java dependency, too.
      If I build without the dependency, it can't find javafx imports.

      Since Java 7 Update 6 it is included in the JDK.
        • 1. Re: Why doesn't Maven find jfxrt.jar, although it is included in the JDK?
          jsmith
          There is a long drawn-out thread on this (you don't need to read it):
          Error initializing OC4J server (JDev 10.1.3 EA1) "JDK 7u6 JavaFX integration - Is jfxrt.jar supposed to be on the classpath?"

          Short summary is that jfxrt.jar is in the jdk/jre as of 7u6, but not on the default classpath for the jdk/jre (as of 7u13).

          This will change in a future release (e.g. I believe the latest early access builds of jdk8 do have jfxrt.jar on the default runtime classpath).
          ----------------------
          So for now, you will need to explicitly add jfxrt.jar to the classpath. There are various ways to do this, one is to use a system dependency and then use the maven ant run plugin to package your app as is done in this example: http://code.google.com/p/willow-browser/source/browse/pom.xml
          <dependency>
            <groupId>javafx</groupId>
            <artifactId>jfxrt</artifactId>
            <version>${javafx.min.version}</version>
            <scope>system</scope>
            <systemPath>${javafx.runtime.lib.jar}</systemPath>
          </dependency>
          ....
          <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.6</version>
            <executions>
              <execution>
                <id>create-launcher-jar</id>
                <phase>package</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <target xmlns:fx="javafx:com.sun.javafx.tools.ant">
                    <taskdef
                        uri="javafx:com.sun.javafx.tools.ant"
                        resource="com/sun/javafx/tools/ant/antlib.xml"
                        classpath="${javafx.tools.ant.jar}"/>
                      <fx:application id="fxApp"
                          name="${project.name}"
                          mainClass="${exec.mainClass}"/>
                      <fx:jar destfile="${project.build.directory}/${project.build.finalName}-launcher">
                        <fx:application refid="fxApp"/>
                        <fx:fileset dir="${project.build.directory}/classes"/>
                      </fx:jar>
                      <attachartifact
                          file="${project.build.directory}/${project.build.finalName}-launcher.jar"
                          classifier="launcher"/>
                  </target>
                </configuration>
              </execution>
            </executions>
          </plugin>
          Another way would be to make use of the zenjava javafx maven plugin:
          http://www.zenjava.com/2012/11/24/from-zero-to-javafx-in-5-minutes/