JavaFX 2.0 and Maven – Part 3

This (hopefully) final instalment of this series of articles on building JavaFX applications with Maven will refine what was done in the previous article. The previous article got us to the point where we were able to build a stand alone JavaFX application this article aims to do that with flare and produce roughly the same output as a regular NetBeans Ant JavaFX project.

The project that I am working on has a dependency on an internal company utilities jar which in turn depends on a bewildering array of other jars. The next step, therefore, is to ensure that this dependency tree is correctly handled by the Maven / Ant hybrid build process. The dependency in the pom looks likes this:


First thing to do is change the output directory for the dependency copy command. The default is a folder called dependencies under the target directory but it would be a lot more convenient if that folder was called lib and under the dist directory we are creating (as is done by NetBeans). So change the dependency copy configuration to:


Notice that I have also excluded the system scope from the copy since there is no point in including the JavaFX runtime in the distribution – it couldn’t run using just this jar file as JavaFX requires significant numbers of native libraries as well.

Now we want to quickly tidy up the fxjar task in the target of the Ant runner plugin. This ensures that the libraries we are using are correctly referenced in the manifest and we include the fallback class (for what it’s worth).

<jfxjar destfile="${}/dist/${}">
	<fileset dir="${}/classes"/>
	<application name="${}" mainClass="[MAIN-CLASS]"/>
		<fileset dir="${}/dist/" includes="lib/*.jar"/>
		<attribute name="JavaFX-Fallback-Class" value="com.javafx.main.NoJavaFXFallback"/>

You should now have a fully working Maven build of a stand alone JavaFX application.

The next step is to get NetBeans to run the application using Maven, Just hitting the big green button on fun produces a stack trace claiming it can’t find the class: javafx.application.Application.

Getting netbeans to run the application turned out to be a lot more difficult than I expected so I’ve put the information on it’s own page.