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, create 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 ![]()



















































Nice, i’ll try this setup! I’m currently looking to use picocontainer for DI in fx beans.
[…] + Maven的开发环境: http://blog.nelsonsilva.eu/2008/10/10/javafx-maven-on-ubuntu/ 注: […]
Hi, how could I compile both Java and JavaFx source file using Maven? With your pom maven compiles only .fx files ignoring completely the standard java source file.
thanks.
I haven’t really tried that. I’m using java sources but they are packaged in another dependency so you could use multiple maven modules to achieve what you want. Basically you have your models and services in a java project with a jar and the view in JavaFX in another one.
If i have some time i can try to get maven to compile both Java and JavaFX and I’ll post it back here in the blog.
Thank you for reply. I will follow your suggestion.
How do you install the mac version of the sdk on ubuntu?
Thanks for a good guide!
I’m having some problems importing my project into Netbeans and making it have javafx “nature” and maven dependencies. If I open it as a Maven project, I can’t seem to launch it as a javafx app.
Any ideas would appreciated!
Cheers.
Hi Viktor,
I’ve setup Netbeans to Run and Debug the project using Maven.
Just go to the project’s properties > Actions
For “Run Project” I’ve got this:
Execute Goals: process-classes org.codehaus.mojo:exec-maven-plugin:1.1:exec” exec.executable=java
Set Properties: exec.args=”-classpath %classpath
For “Debug Project” :
Execute Goals: process-classes org.codehaus.mojo:exec-maven-plugin:1.1:exec” jpda.listen=true exec.executable=java
Set properties: exec.args=”-Xdebug -Djava.compiler=none -Xnoagent -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath
Hope this helps…
Which Maven version was used in this article’s example? I’m using 2.0.9 and it complains that “system-scoped dependency must specify an absolute path systemPath”. systemPath is absolute path but after expanding parameter value which seems not to occur. There are two issues in Maven JIRA related to this, http://jira.codehaus.org/browse/MNG-2626 and http://jira.codehaus.org/browse/MNG-2694 so I wonder how did you make example work before these issues are fixed?
Solved it - paths to jars in JavaFX SDK 1.1 are different, and also m2eclipse 0.9.7 pom editor with embedded maven wrongly reports that systemPath is not absolute if it contains reference to variable, so with external maven and jar path adjusted things started working well. Thanks for sharing the article!
[…] and Maven Filed under: Java, JavaFX, Maven — karussell @ 7:41 pm There is a post which discusses all the details about how to set up JavaFX in a maven […]
Nice, i’ll try this setup! I’m currently looking to use picocontainer for DI in fx beans.
Hey I’d love to congratulate you for such a terrific made site!
Just thought this would be a nice way to introduce myself!
Sincerely,
Robin Toby
if you’re ever bored check out my site!
fiesta Party Supplies.
Don’t you love me
You can find my pics here
My Profile
Good work, your articles are very interesting, i am glad that i googled your blog
What template do you use in your blog ? Looks cool
You have a lot of interesting articles here, but you must improve your blog design
Bonjour I’d love to congratulate you for such a terrific made site!
Just thought this is a perfect way to introduce myself!
The best way gain property it is usually a good plan to start a savings or investing course of action as soon in life as obtainable. But don’t despair if you have not started saving your assets until later on in life. As a result of honest work, that is consulting the best investment vehicles for your capital you can slowly but surely increase your wealth so that it numbers to a sizable amount by the time you hope to retire. Contemplate all of the accessible asset classes from stocks to real estate as investments for your money. A knowledgeable and diversified portfolio of investments in a wide range of asset classes may make your money advance throughout the years.
-Ashlee Markgraf
currency exchange rates
Hello. My wife and I bought our house about 6 months ago. It was a foreclosure and we were able to get a great deal on it. We also took advantage of the 8K tax credit so that definitely helped. We did an extensive remodeling job and now I want to refinance to cut the term to a 20 or 15 year loan. Does anyone know any good sites for mortgage information? Thanks!
Mike
I came across your article, and i think you are very good writer, keep us posting