Coming Up for Air

JavaFX and Maven

I’ve been tinkering with a couple of different JavaFX projects for a while now. Due to other commitments, they’ve been largely ignored recently, but I made some time this weekend to return to them. Since I last looked at them, Java 8, and, thus, JavaFX 8, have been release, so I decided to see how the tooling in NetBeans has changed to stay apace with the development of the libraries. While there are certainly updates, it seems new projects are still built using Ant. Yuck. :P I knew Adam Bien had a Maven archetype for his igniter.fx project, so I took a look to see what that POM does to support JavaFX. As it turns out, it’s pretty simple. For those interested, I have extracted here the basic POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=""

        <defaultGoal>clean package</defaultGoal>

The interesting parts are the two plugins, maven-dependency-plugin and exec-maven-plugin. The first takes all of the non-system-scoped dependencies, and extracts the jars into ${}/classes. This makes the dependencies available to the application without having to manage a bunch of jars, which is helpful when distributing the app. Speaking of which, the next plugin, exec-maven-plugin, packages the application as a JAR using the javafxpackager tool in JAVA_HOME (make sure you change MAIN_CLASS ;). Once you package the app, it can be run with a simple java -jar target/ARTIFACT_NAME-app.jar.

While this POM differs a bit from Adam’s POM (e.g., I keep the resources, such a .fxml files, in the standard Maven location), NetBeans is more than happy with it, and my JavaFX hacking is a bit simpler.

tags: JavaFX Maven


Sample quote

Quote source