JavaFX and Maven

There is a post which discusses all the details about how to set up JavaFX in a maven project (compiling etc).

For my timefinder project I only need a solution where I can use a JavaFX-jar within my maven project. This is a little bit faster to achieve:

  1. First, be sure you set up JavaFX correctly. For linux and JavaFX 1.1 you can try this.
  2. Now write the following in your /home/user/.m2/settings.xml:
    <settings>
      <profiles>
        <profile>
          <id>test</id>
          <activation>
            <property>
                    <name>!javafx_home</name>
            </property>
          </activation>
            <properties>
                <!-- linux -->
                    <javafx_home>/home/user/programs/netbeans-6.5/javafx2/javafx-sdk1.0</javafx_home>
                <!-- windows
                    <javafx_home>C:\Program Files\NetBeans 6.5\javafx2\javafx-sdk</javafx_home> -->
            </properties>
         </profile>
      </profiles>
      ...
    </settings>
  3. After this you can include the javafx libraries in your pom.xml:
    <project>
      ...
      <dependencies>
           ...
            <dependency>
                <groupId>com.sun.javafx.rt15</groupId>
                <artifactId>javafx-rt15</artifactId>
                <version>1.0</version>
                <scope>system</scope>
                <systemPath>${javafx_home}/lib/desktop/rt15.jar</systemPath>
            </dependency>
            <dependency>
                <groupId>com.sun.javafx.gui</groupId>
                <artifactId>javafx-gui</artifactId>
                <version>1.0</version>
                <scope>system</scope>
                <systemPath>${javafx_home}/lib/desktop/javafxgui.jar</systemPath>
            </dependency>
            <dependency>
                <groupId>com.sun.javafx.rt</groupId>
                <artifactId>javafx-rt</artifactId>
                <version>1.0</version>
                <scope>system</scope>
                <systemPath>${javafx_home}/lib/shared/javafxrt.jar</systemPath>
            </dependency>
            <dependency>
                <groupId>com.sun.javafx.eula</groupId>
                <artifactId>javafx-eula</artifactId>
                <version>1.0</version>
                <scope>system</scope>
                <systemPath>${javafx_home}/lib/desktop/eula.jar</systemPath>
            </dependency>
            <dependency>
                <groupId>com.sun.javafx.scenario</groupId>
                <artifactId>javafx-scenario</artifactId>
                <version>1.0</version>
                <scope>system</scope>
                <systemPath>${javafx_home}/lib/desktop/Scenario.jar</systemPath>
            </dependency>
            <dependency>
                <groupId>com.sun.javafx.swing</groupId>
                <artifactId>javafx-swing</artifactId>
                <version>1.0</version>
                <scope>system</scope>
                <systemPath>${javafx_home}/lib/desktop/javafx-swing.jar</systemPath>
            </dependency>
            <dependency>
                <groupId>com.sun.javafx.jmc</groupId>
                <artifactId>javafx-jmc</artifactId>
                <version>1.0</version>
                <scope>system</scope>
                <systemPath>${javafx_home}/lib/desktop/jmc.jar</systemPath>
            </dependency>
            <dependency>
                <groupId>com.sun.javafx.websvc</groupId>
                <artifactId>javafx-websvc</artifactId>
                <version>1.0</version>
                <scope>system</scope>
                <systemPath>${javafx_home}/lib/desktop/websvc.jar</systemPath>
            </dependency>
            <dependency>
                <groupId>com.sun.javafx.scriptapi</groupId>
                <artifactId>javafx-scriptapi</artifactId>
                <version>1.0</version>
                <scope>system</scope>
                <systemPath>${javafx_home}/lib/desktop/script-api.jar</systemPath>
            </dependency>
            <!-- The javafx dependencies are taken from the profiles/desktop.properties file-->
        </dependencies>
    </project>
  4. That’s it! Now you should be able to use javafx or javafx-components in you fancy application. In the most cases you might be interested in one of my previous posts, which discusses how to embed a javafx-component into an existing Swing-application.