How To Compile Java FX 2 Applications With Maven 3

Java FX 2 is Java. To build a Java FX application you only need an additional JAR: jfxrt.jar which contains the Java FX UI classes. The JAR comes with Java FX SDK, but is not included in the public maven repository. You can point to the Java FX SDK installation with Maven's system scope dependency:


<project>
...
    <dependencies>
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>javafx</artifactId>
            <version>2.0</version>
            <systemPath>${fx.home}/rt/lib/jfxrt.jar</systemPath>
            <scope>system</scope>
        </dependency>
    </dependencies>
</project>

The resolution of the ${fx.home} variable ensures the pom.xml independency on user-specific settings:

<settings>
...
<profiles>
        <profile>
            <id>javafx</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <fx.home>[PATH]/javafx-sdk2.1.0-beta/</fx.home>
            </properties>
        </profile>
    </profiles>
</settings>

Comments:

Instead of forcing the definition of a profile and fx.home property, you might consider doing it like so:

<dependency>
<groupId>com.oracle</groupId>
<artifactId>javafx</artifactId>
<version>${javafx.version}</version>
<systemPath>${java.home}/lib/jfxrt.jar</systemPath>
<scope>system</scope>
</dependency>

This way, as long as you have JavaFX installed in your JVM folders, it's a bit simpler ;)

Posted by Pedro Assunção on June 27, 2012 at 03:54 PM CEST #

Hi, Adam, great post!

I tried your solution, but I'm getting "java.lang.NoClassDefFoundError: javafx/application/Application"

is there something else to set up to get javafx running on Maven 3 ?

thanks

Posted by Rafael Nascimento on October 26, 2012 at 06:31 PM CEST #

You can to use this link: http://ideashare.net/java/javafx-noclassdeffounderror/

In my case it help.

Posted by Jon on February 28, 2014 at 09:29 PM CET #

Is this outdated since it's possible to just use JavaFX by including the following dependency or am I missing something (very likely since I'm just starting in this JavaFX/Maven world?
<dependency>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.1.2</version>
</dependency>

Posted by Zapatilla on February 26, 2015 at 06:01 PM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments
License