« Back to blog

JavaFX + Maven on Ubuntu

Well, I've been following JavaFx for a long time but I've only started trying out yesterday. I need to create some GUI for testing some libraries I've been working on and I felt this was the right time to try out JavaFX.

The first challenge was to get the JavaFX Preview SDK working on my Ubuntu machine. After googling around I found that the MacOSX version of the SDK works on Linux so I downloaded it from here.
Then I got the Netbeans JavaFX Plugin from the JavaFX_NB_Daily project.
After installing the nbms I decided to switch the SDK provided by the plugin with the one I downloaded from Sun's JavaFX page. For that I went into my netbeans directory "~/netbeans6-1" onto the "javafx" directory, renamed the sdk dir and unziped sun's sdk. This step is probably not necessary but I'd like to make sure I was working with Sun's JavaFX SDK.
Well, with everything setup I started netbeans, created a project with the sample weather app and it ran just fine :)
The next step was to get maven to compile a JavaFX project. I normally have several dependencies for each new project and I've really come to appreciate Maven for dealing with these for me. Again I googled for it and found this: http://m2-javafxc.sourceforge.net/. Well it did what I needed, just had to figure out how to use my javafxc compiler. This is what I came up with in the end:

<?xml version=”1.0″ encoding=”UTF-8″?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>pt.inevo.javafx</groupId>
<artifactId>javaFXMaven</artifactId>
<name>javaFXMaven</name>
<version>1.0</version>
<url>http://www.inevo.pt</url>
<properties>
<javafx.home>/home/nfgs/netbeans-6.1/javafx/javafx-sdk1.0pre1</javafx.home>
<netbeans.hint.useExternalMaven>true</netbeans.hint.useExternalMaven>
</properties>
<dependencies>
…
<dependency>
<groupId>javafx</groupId>
<artifactId>javafxrt</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${javafx.home}/lib/javafxrt.jar</systemPath>
</dependency>
<dependency>
<groupId>javafx</groupId>
<artifactId>javafx-swing</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${javafx.home}/lib/javafx-swing.jar</systemPath>
</dependency>
<dependency>
<groupId>javafx</groupId>
<artifactId>Scenario</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${javafx.home}/lib/Scenario.jar</systemPath>
</dependency>
<dependency>
<groupId>javafx</groupId>
<artifactId>javafxgui</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${javafx.home}/lib/javafxgui.jar</systemPath>
</dependency>
</dependencies>
<pluginRepositories>
<pluginRepository>
<id>m2-javafxc</id>
<name>Sourceforge M2-javafxc static repo</name>
<url>http://m2-javafxc.sourceforge.net/m2repo</url>
</pluginRepository>
</pluginRepositories>
<build>
<sourceDirectory>src/main/javafx</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerId>javafxc</compilerId>
<include>**/*.fx</include>
<compilerArguments>
<jfxHome>false</jfxHome>
</compilerArguments>
</configuration>
<dependencies>
<dependency>
<groupId>net.sf.m2javafxc</groupId>
<artifactId>plexus-compiler-javafxc</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>javafx</groupId>
<artifactId>javafxc</artifactId>
<version>0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${javafx.home}/lib/javafxc.jar</systemPath>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>fxsketch.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>

Now I can store my code in src/main/javafx and just open my project with netbeans (since it reads the pom.xml file). I'm using the external maven since I've had a few problems with the internal version. I hope this helps some of you. I'm really starting to appreciate JavaFx and can't wait to get the Media SDK and the SG3D to really come up with something interesting ;)

Posted at 10 Oct 2008
Filed under: