Friday, January 18, 2013

ScalaFX - A DSL for JavaFX in Scala

ScalaFX is an opensource project which aims to provide a concise DSL for using JavaFX with Scala.

Scientific apparatus, 1939, 1
Scientific apparatus, 1939, 1

Only very recently the ScalaFX project was restructured and it is now easier to set it up and build it - Peter Pilgrim did a great job setting up the sbt build. I want to describe what is necessary to get a maven project running which uses the ScalaFX project.

7 Steps to a running ScalaFX application with maven

(If you have tried out examples of this blog you may have installed the prerequisites already, so you can skip until step 1.):

-4) Make sure maven is installed:

Get it at here.

-3) Install Mercurial: 

Get it here.

-2) Make sure you are using a recent JDK (1.7.11 or newer):

Get it here.

-1) Install the simple build tool for scala

Get it here.

0) Execute following command and say "Y"

mvn com.zenjava:javafx-maven-plugin:1.3:fix-classpath

Ok, now you should be set up. Now the ScalaFX specific steps start.

1.) Check out the ScalaFX source code

hg clone

2.) Install it into your local maven repository

In short:

sbt clean compile package make-pom package-src make-pom

mvn install:install-file -DartifactId=scalafx_2.9.2 \
    -DgroupId=org.scalafx \
    -Dpackaging=jar \
    -DpomFile=scalafx-core/target/scala-2.9.2/scalafx-core_2.9.2-1.0-SNAPSHOT.pom \
    -Dfile=scalafx-core/target/scala-2.9.2/scalafx-core_2.9.2-1.0-SNAPSHOT.jar \
    -Dversion=1.0-SNAPSHOT \

will place a maven artifact in your local repository and suddenly you are ready to start coding with ScalaFX. (Skipping tests is of course bad and ugly ;-) )

You have to reference it from any maven project via


3) Final step: Clone example project

Anyhow, after going through all this you can clone the scalafx-example project from github. It contains a ScalaFX program which looks like this:


You can import the project into Eclipse via "Import maven projects" or compile it on the command line via

mvn clean package


java -jar target/scalafx-example-1.0-SNAPSHOT-jfx.jar 

will show you the following:

ScalaFX HelloWorld

For more information about ScalaFX,  go to

No comments:

Post a Comment