How to build and package JavaFX 2 Application with Maven

I hate Ant, and I can’t begin to work on a project that requires using it.

So like many people I want to build my brand new JavaFX 2 applications with the best toolchain available for Java : Maven.

I planned to create a custom maven-plugin to do the job, but by using existing ones we can do it.
Some things must be improved but the essential works.

The results is a zip file containing all dependencies (jar) with a jnlp file used to launch the application online or offline.

A demo application is currently visible on the JRebirth website. I used the html template generated by the javafxpackager tool.

Here you have the pom.xml file of the JavaFX application.

You can browse the svn source repository to show more information about the demo project at [|]:

The Pom that rules the maven Build pom.xml

<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
	<name>JavaFX 2.0 Presentation</name>
	<description>Interactive Presentation of JavaFX2 capabilities</de
        <!-- not used yet -->

               <!-- Include FXML resources -->

					<encoding>UTF-8</encoding><!-- try to force encoding --> 

								jaxb-api-2.2.1.jar stax-api-1.0-2.jar activation-1.1.jar
								jaxb-impl-2.2.1.jar core-0.4.0-SNAPSHOT.jar
							<goal>jnlp</goal> <!-- use jnlp, jnlp-inline or jnlp-single as appropriate -->
					<!--outputDirectory></outputDirectory --> <!-- not required?? -->

					<!-- Set to true to exclude all transitive dependencies. Default is false. -->

					<!-- The path where the libraries are stored within the jnlp structure. not required. by default the libraries are within the working directory -->
					<!-- <libPath>lib</libPath> -->
					<!-- [optional] transitive dependencies filter - if omitted, all transitive dependencies are included -->
					<!-- <dependencies> Note that only groupId and artifactId must be specified here. because of a limitation of the Include/ExcludesArtifactFilter <includes> <include>org.jrebirth:presentation</include> 
						<include>org.jrebirth:core</include> </includes> excludes> <exclude></exclude> <excludes </dependencies> -->
					<!--resourcesDirectory>${project.basedir}/src/main/jnlp/resources</resourcesDirectory --> <!-- default value -->

					<!-- JNLP generation -->
						<!-- default values -->
						<!--inputTemplateResourcePath>${project.basedir}</inputTemplateResourcePath -->
						<!--inputTemplate>src/main/jnlp/template.vm</inputTemplate --> <!-- relative to inputTemplateResourcePath -->
						<outputFile>Prez.jnlp</outputFile> <!-- defaults to launch.jnlp -->
						<!-- used to automatically identify the jar containing the main class. -->
						<!-- this is perhaps going to change -->

					<!-- SIGNING -->
					<!-- defining this will automatically sign the jar and its dependencies, if necessary -->
						<keystore>${basedir}/jrebirth.jks</keystore><!-- Used a pre-generated keystore -->
						<keypass>gojava</keypass>  <!-- we need to override passwords easily from the command line. ${keypass} -->
						<storepass>gojava</storepass> <!-- ${storepass} -->
						<!--storetype>fillme</storetype -->

						<!--validity>fillme</validity -->
						<!-- only required for generating the keystore -->
						<!--dnameCn>fillme</dnameCn> <dnameOu>fillme</dnameOu> <dnameO>fillme</dnameO> <dnameL>fillme</dnameL> <dnameSt>fillme</dnameSt> <dnameC>fillme</dnameC -->
						<verify>true</verify> <!-- verify that the signing operation succeeded -->
						<!-- <keystoreConfig> <delete>true</delete> delete the keystore <gen>true</gen> optional shortcut to generate the store. </keystoreConfig> -->

					<!-- BUILDING PROCESS -->
					<gzip>false</gzip> <!-- default force when pack200 false, true when pack200 selected ?? -->
					<!-- causes a version attribute to be output in each jar resource element, optional, default is false -->
					<!-- <outputJarVersions>true</outputJarVersions> -->
					<!--install>false</install --> <!-- not yet supported -->


I choose to deploy the ”jfxrt.jar” into my maven repository to have a cross-platform build independantly of JavaFX Runtime installation.

Maven build doesn’t require Dlls (or .so files) dependencies, it just need the JavaFX api jar (jfxrt.jar), thus we can manage several javafx versions.

An alternative is to provide the jar with system scope by usin a ”JAVAFX_HOME” environment variable :

    <systemPath>C:/Program Files/oracle/jfx2.0/rt/lib/jfxrt.jar</systemPath><!-- should use environment variable for cross-platform-->

Jnlp Template for JavaFX 2

The jnlp file template that you must use :

It could be improved by adding runtimes for all operating system.


<?xml version="1.0" encoding="UTF-8" ?>
<jnlp spec="1.0+" xmlns:jfx="" href="Prez.jnlp">
	<!-- codebase="" for online-->
		<vendor>Sébastien Bordes</vendor>
		<homepage href="${project.url}"/>
		<!--<description kind="short"></description>-->
		<!--<icon href="icon.png"/>-->


	<resources os="Windows" arch="x86">
		<jfx:javafx-runtime version="2.0+" href=" "/>
	<resources os="Windows" arch="x64">
		<jfx:javafx-runtime version="2.0+" href=" "/>

		<j2se version="1.7+" />
		<property name="file.encoding" value="UTF-8"/>

	<applet-desc  width="1024" height="768" main-class="com.javafx.main.NoJavaFXFallback"  name="${}" />
	<jfx:javafx-desc  width="1024" height="768" main-class="$mainClass"  name="${}" />

	<update check="background"/>

Developper launching

I’m using __[e(fx)clipse|]__ to write code.

I launch the application from eclipse IDE, and to do the ‘Dlls” trick, I copy the bin folder (that store all Dlls) into the parent folder of the ”jfxrt.jar” stored into my maven repository.
It’s only used to launch the application from Eclipse. A better way will be to store them into the maven repository but It’s quite painful…
When you launch the jnlp file, you will use the default JavaFX runtime installed on your platform.

[((/public/javafx2/ci_cd/.Bin_Trick_m.jpg|Bin_Trick.png||Bin_Trick.png, jan 2012))|/public/javafx2/ci_cd/Bin_Trick.png]

Continuous Delivery

Then you can add a FTP transfer task into your Continuous Integration (obviously I use [jenkins for JRebirth|]) to allow continuous delivery to your favorite project.

[((/public/javafx2/ci_cd/.Continuous_Delivery_m.jpg|Continuous_Delivery.png||Continuous_Delivery.png, jan 2012))|/public/javafx2/ci_cd/Continuous_Delivery.png]

So __JavaFX 2__ ”Rocks” with __Maven__, and even with your favorite software factory tools ! (You can have a look at [JRebirth contribute|] page to see which other softwares I use)

{{Enjoy JavaFX with Maven !!}}

[((|Wordle: Maven JavaFX2 Tutorial||Wordle: Maven JavaFX2 Tutorial))|]

Leave a Reply