twitterfx_logo_big_shaddow

Maven and JavaFX, the story of TwitterFX POM

JavaOne demo

Our JavaOne 2009 technical presentation TS-4388 is a demo integrating Maven, JavaFX, Artifactory and WebStart in one smooth process for the developer and site operation manager.
So, we were looking for a nice JavaFX demo with source code using external Java dependencies that will demonstrate the ease of use of Maven when using Java libraries. From the JavaFX Application contest and from some Twitter news we tried TwitterFX.
We were immediately impressed by the UI quality and slickness of this application: Bravo!
So we checked out the source code, and we saw the need for Maven on this project. All the dependent jars were included in Subversion (3.1M of jars out of a 4.2M project: 74%), and the generated build scripts generated by Netbeans are hard to maintain for users without the IDE. Managing Hudson builds without NetBeans becomes almost impossible.

JavaFX and Maven

We looked for java developers that already tried to merge these 2 technologies, and found out that few actually succeeded. We were looking for a clean integration with minimal POM configuration.

  1. For compiling JavaFX code, we found:
  2. For generating JNLP files, the WebStart plugin is working correctly but it is flattening the references to external jars. It means that all dependent jars are copied in the same folder than the jar of your application. We want to avoid the duplication of jars in the end user WebStart cache, so we liked to use the maven repository layout format for referencing jars.

So, we wrote 2 Maven plugins:

    1. JavaFX Compiler Maven Plugin: compile javafx source files without interfering with the java compiler. It activates the javafxc Ant task using the Maven model to fill the classpath and other parameters.
    2. JNLP Generator Maven Plugin: The plugin will activate Velocity to generate a JNLP file out of the master template and all Maven model data (your project information) and especially maven runtime dependencies. The generated JNLP file will be distributed by Maven automatically.

We used them first on the small demo that depends only on the JavaFX platform, then we used them to “Mavenize” the TwitterFX code base.
So, here is the source code for the Maven version of TwitterFX. In this check out there are no jars in Subversion, no Ant build script, and no classpath. There was 500 lines of Ant code (XML and properties files, managed and generated by NetBeans), that became 200 lines in the POM file (and can be a lot smaller). The main difference is that the POM file is readable and maintainable.
To build it, you’ll need java 6, Maven 2.0.9 or above (2.1 recommended) and to run “mvn -Pjfrog install”.
We still have one issue today: It is not possible to create a Maven AND JavaFX project inside NetBeans (NetBeans: Maven + JavaFX project? – The Java Posse | Google Groups).

Deploying the Application

In a modified version of Artifactory we are managing WebStart requests toward JNLP and jar files. This extension provides codebase modification of JNLP file attribute based on the server settings, and on-the-fly signing of the main jar and its dependencies. If you deployed a JNLP applet you can even preview it directly from Artifactory!

Using the Maven 2 repository layout to reference third party jars allows the end user WebStart cache to reuse the dependent jars URL. To avoid users re-downloading common jars between javafx examples, the javafx.com demo files are all uploaded at the root of this server!

 

Leave a Reply

Please type the code shown*


Can't read the image? click here to refresh