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

Hendrik Ebbers

Hendrik Ebbers is the founder of Open Elements. He is a Java champion, a member of JSR expert groups and a JavaOne rockstar. Hendrik is a member of the Eclipse JakartaEE working group (WG) and the Eclipse Adoptium WG. In addition, Hendrik Ebbers is a member of the Board of Directors of the Eclipse Foundation.

Circle Circle
logo

Open Source made right

Privacy

Privacy Policy Cookie Policy Privacy Config Impressum