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 [source.jrebirth.org|http://source.jrebirth.org]:

The Pom that rules the maven Build pom.xml

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 :

Jnlp Template for JavaFX 2

The jnlp file template that you must use :

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

src/main/jnlp/template.vm

Developper launching

I’m using __[e(fx)clipse|http://efxclipse.org/]__ 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|http://ci.jrebirth.org]) 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|http://www.jrebirth.org/contribute.html] page to see which other softwares I use)

{{Enjoy JavaFX with Maven !!}}

[((http://www.wordle.net/thumb/wrdl/5080206/Maven_JavaFX2_Tutorial|Wordle: Maven JavaFX2 Tutorial||Wordle: Maven JavaFX2 Tutorial))|http://www.wordle.net/show/wrdl/5080206/Maven_JavaFX2_Tutorial]

Leave a Reply