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

11 Responses to Building JavaFX Applications with Maven

  1. I’m having java 6 update 29 on win7 64bit, this doesn’t work for me. I’ve checked but there’s no jar with this name. May be you can consider updating your article.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>