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 ;)

20 Comments so far

  1. devantor on October 11th, 2008

    Nice, i’ll try this setup! I’m currently looking to use picocontainer for DI in fx beans.

  2. […] + Maven的开发环境: http://blog.nelsonsilva.eu/2008/10/10/javafx-maven-on-ubuntu/ 注: […]

  3. Noname on October 30th, 2008

    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.

  4. admin on October 30th, 2008

    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.

  5. Noname on October 30th, 2008

    Thank you for reply. I will follow your suggestion.

  6. sander on January 21st, 2009

    How do you install the mac version of the sdk on ubuntu?

  7. Viktor Nordling on February 2nd, 2009

    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.

  8. admin on February 2nd, 2009

    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
    Set Properties: exec.args=”-classpath %classpath ” exec.executable=java

    For “Debug Project” :

    Execute Goals: process-classes org.codehaus.mojo:exec-maven-plugin:1.1:exec
    Set properties: exec.args=”-Xdebug -Djava.compiler=none -Xnoagent -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath ” jpda.listen=true exec.executable=java

    Hope this helps…

  9. Stevo Slavic on February 18th, 2009

    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?

  10. Stevo Slavic on February 18th, 2009

    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!

  11. […] 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 […]

  12. PB on May 27th, 2009

    Nice, i’ll try this setup! I’m currently looking to use picocontainer for DI in fx beans.

  13. chepcedaDooke on January 10th, 2010

    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.

  14. HoneyBunnyyyy on January 14th, 2010

    Don’t you love me

    You can find my pics here

    My Profile

  15. resveratrol on January 29th, 2010

    Good work, your articles are very interesting, i am glad that i googled your blog

  16. anti aging product on February 5th, 2010

    What template do you use in your blog ? Looks cool

  17. download from redtube on February 24th, 2010

    You have a lot of interesting articles here, but you must improve your blog design

  18. excelmanking on March 3rd, 2010

    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

  19. mikejohnsonrules on March 10th, 2010

    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

  20. unlock codes on March 10th, 2010

    I came across your article, and i think you are very good writer, keep us posting

Leave a Reply