A Maven archetype for JavaFX 2.0 in Scala

I have created a simple Maven archetype for building standalone JavaFX 2.0 applications written in Scala. The generated Scala code is a close translation of the Java code for the Colorful Circles demo in Oracle’s Getting Started with JavaFX tutorial. Here’s how it looks:

Prerequisites

You need to have the following installed:

  1. JDK 1.6 or later.
  2. JavaFX 2.0 SDK Beta or later.
  3. Maven 3.0.3 or later.

Obviously, using an IDE is a nice option, for example NetBeans 7.0.1.

Setup

Before you can use a generated project you need to set the environment variable JAVAFX_HOME to the sub-directory bin of the installation directory for JavaFX 2.0 SKD, C:Program FilesOracleJavaFX 2.0 SDKbin for example. Setting the environment variable to this sub-directory has the additional benefit that it makes the javafxpackager utility work as designed, even though this utility is not used by the generated project.

Generation

Now use your favorite IDE to generate a project from the Maven archetype with the coordinates:

<dependency>
    <groupId>de.schlichtherle</groupId>
    <artifactId>javafx-scala-demo</artifactId>
    <version>0.3</version>
</dependency>

If you’re not using an IDE, then run maven from a shell as follows:

$ mvn archetype:generate -Dfilter=de.schlichtherle:javafx-scala-demo

When prompted, select the latest version and answer the next prompts for the group ID, artifact id, version and package name for the generated project.

Building

Now you can use your IDE to open the generated project directory. If you are using NetBeans, just press the “run” button to watch Maven building and running the demo application.

If you’re not using an IDE, then change to the generated project directory and enter the following to build the demo application:

$ mvn install

To run the demo application, enter the following:

$ java -jar target/*-jar-with-dependencies.jar

Enjoy!