JavaFX 2.2 and Maven

JavaFX 2 did get my acceptance when it suddenly without warning became bundled with the JDK. When that happened, I started considering JavaFX to be a real alternative and something to take into consideration when building a RIA application. The logic in this can be questioned, but this was what I felt.

JavaFX 2 replaces Swing (thanks Oracle!) and with it I believe that we finally have a decent RIA framework for Java. It would have been nice if this happened many years ago, but I do not think it’s too late. For what I can see, there are many developers out there who would like to develop user interface applications in Java using a modern user interface framework but consider Swing old and bloated, current Java web frameworks out there time consuming for creating user interfaces that look nice, respond fast and behave good, and are not comfortable with Javascript, or any other current web client technology.

First start out with installing the latest and greatest Java7u7 or later. It bundles JavaFX. Then create a small JavaFX 2 skeleton application:

package se.marell.jfxskeleton;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class Main extends Application {
  public static void main(String[] args) {

  public void start(Stage primaryStage) {
    primaryStage.setTitle("jfx skeleton");

    Button button = new Button("Button");
    BorderPane panel = new BorderPane();

    button.setOnAction(new EventHandler() {
      public void handle(ActionEvent actionEvent) {
        System.out.println("Button event, playing sound");
        AudioClip plonkSound = new AudioClip("");;

    Scene scene = new Scene(panel, 200, 200);

When using normal UI components like buttons and panels, the programming model should feel almost like home if you are familiar with Swing, Android or Vaadin.

Running the app in Intellij IDEA 11 by just pressing the Run button works like a charm,

but building it with Maven fails with a compilation error:

error: package javafx.application does not exist

It turned out that the job Oracle did was not completely finished, because JavaFX has not been added to the standard classpath.

There are a number of possible technical work-arounds for this classpath/separation problem. One is to add javafx as a system dependency:


A solution that works better with Maven is to install JavaFX 2 in your local maven repo. This is a one-time operation. It can be done by adding a snippet of Maven configuration described here. In order to make it work also on OS X you must also must include the dylib files in the bin folder (see source link below).

To your settings.xml, add the system dependent property jfx-runtime, something like this:

<settings xmlns=""



Run this command once: mvn -Pinstall-javafx install

Now you are ready to add javafx 2.2 to your pom as a plain Maven dependency:


When JavaFX 2 in a future becomes integrated with the JDK, this dependency can be removed, and then everything will just continue to work.

Full code is available here:

The bundling of JavaFX 2 in the JDK without adding it to the standard classpath actually does not change anything, compared to when JavaFX 2 was a separate download, except for Oracle to indicate the intention to really integrate the two in a hopefully not too far future.

Oracle, please repair the JavaFX 2 distribution license and please add JavaFX to the standard classpath!

EDIT 2015-07-07: With Java 8 this just works without any hazzle. See

IT Consultant at CAG Contactor. Software developer and architect focused on Java EE/SE.

Publicerad i Java, OS X
5 comments on “JavaFX 2.2 and Maven
  1. Daniel Marell skriver:

    The javadoc for JavaFX is not bundled with the JDK nor with the JDK javadoc, it has to be downloaded and installed separately.

    The below steps will bundle the javadoc in the javafx:javafx:2-2 artifact. The below description is for Linux/Ubuntu, but Windows-users can probably make use of this too:

    First download the javadoc. This is not as easy to find it by navigating the website, at least when I tried, but here’s a link:
    The downloaded file is
    $ cd /usr/lib/jvm/jdk1.7.0
    $ mkdir docs
    $ cd docs
    $ mv ~/Downloads/ ./
    $ cd ~/jfxskeleton
    $ rm -rf ~/.m2/repository/javafx/javafx/2.2
    $ cd jfxskeleton
    $ mvn -Pinstall-javafx install

  2. Venkat skriver:

    Thanks a lot, I finally got it working after toiling for two hours.

  3. Gene De Lisa skriver:

    You can use the java.home property.

  4. Gene De Lisa skriver:

    I wrapped my example in the tag, yet your commenting system ate the xml tags.

  5. Daniel Marell skriver:

    Thanks Gene, by using ${java.home} with JavaFX I think we hit one of the situations where the system scope actually is the right solution with Maven.

    We have to setup the javadoc in a separate step but that is done once and in the same way you set it up for the JDK. That makes sense.

    I tried out a couple of WordPress plugins in order to enable html/xml in the text but I could not get it working. I had to write the xml snippet below with HTML character entities ( & g t ; ).

    This is probably what you wrote in your comment above:


1 Pings/Trashbacks för "JavaFX 2.2 and Maven"
  1. […] Daniel Marell shows how to build JavaFX projects with Maven […]


LinkedIn Auto Publish Powered By :