Building JavaFX Applications with Maven

There are already a lot of posts out there that describe a workflow for integrating JavaFX in Maven. Here is one example by Adam Bien: http://www.adam-bien.com/roller/abien/entry/how_to_compile_java_fx

For all this solutions you have to specify your system-specific path to the JavaFX installation. You can set the property inside your Maven pom. This is ok for a single user environment but counterproductive when developing in a team. Another way is to set the property on OS Level. But then every developer have to do this on every workstation.

Since Java 7 update 6 JavaFX 2.2 is bundled  in the JRE. You can find JavaFX at JAVAHOME/lib/jfxrt.jar. Since Maven 3 you can access the JAVAHOME path with the ${java.home} property. With this informations you are able to create a system independent pom-file:

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

The solution is working since Java 7u6. If you have different JDKs / JREs installed on your system you have to start Maven with the right JDK. The pom also works in Eclipse with m2eclipse-plugin. Here you must ensure that Eclipse is started with Java 7u6+.

7 Responses to Building JavaFX Applications with Maven

  1. [...] Ebbers has also posted two posts this week. Firstly he has a post about building JavaFX applications with Maven, and secondly about adding JavaFX to your Eclipse [...]

  2. [...] Ebbers has also posted two posts this week. Firstly he has a post about building JavaFX applications with Maven, and secondly about adding JavaFX to your Eclipse [...]

  3. zonski sagt:

    You might be interested in this plugin:

    https://github.com/zonski/javafx-maven-plugin

    Use mvn jfx:fix-classpath command to put jfxrt.jar on the jre path (which is what will happen in future releases by default).

    This also can be used for assembling executable jars and/or native installers from maven.

  4. Nico sagt:

    simple yet elegant, nice

  5. [...] you are interested in how we added JavaFX as a dependency to DataFX you can read here about [...]

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

Du kannst folgende HTML-Tags benutzen: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>