JavaFX + Maven on Ubuntu 13

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

RIA Wars 1

The growing bandwith has allowed developers to provide rich Web based user interfaces and thus bring together Web and Dektop applications.

You have Javascript with several new libraries sprouting almost everyday, this allows us to bring live to otherwise static HTML pages through manipulation of the DOM and using AJAX calls to get data from the server.

Nonetheless javascript depends on the browser’s implementation and your source code is there for anyone to see. AJAX calls are pretty cool but XML is a major overhead with large messages and slow parsing.

Adobe has a huge browser penetration, close to 98% if i’m not mistaken. Most people dislike Flash and think it is only used by designers to create sexy and annoying banners. The truth is that Flash uses Mozilla’s Tamarin VM for running ActionScript. Both Javascript and ActionScript are ECMAScript but with ActionScript you have the advantage that it get’s compiled and your source code is not there for anyone to see (unless they disassemble it). Besides, to reproduce most of the functionality you get with Flash you need a lot of javascript libraries, especially if we’re using Flex. Flex provides us a growing number of prebuild components and the UI is specified using MXML with offers a clear separation of controller and view. What’s more upcoming versions of Flash will enable browsers to cache commonly used flash modules (like the Flex framework) so, you only download the library the first time you visit a site using Flex.

The AMF protocol, used by Flash is now Open and there is a reference implementation freely available. This binary protocol is a lot faster than using XML or JSON and it supports pushing information thus we don’t need to have clients constantly pooling our server.

There are some more contenders in this RIA war, JavaFX and Silverlight.

JavaFX suffers, for now, from the same problems every JAVA applet has. It does not fit well in a page, it takes too long to load and there are still many people without JAVA. When JAVA offers an easier instalation and preloads in the OS’s memory then we could have a serious alternative but for now.. well it is just not up to the challenge.

Silverlight has some cool ideas, it allows us to program in a myriad of languages since they share a common runtime, has hardware acceleration and, since it is from Microsoft will come preinstalled in Windows machines. Still, there is no real showcase (Microsoft is using it to build a part of their site now in beta), there have been a couple of releases which were incompatible with each other (you had to keep reinstalling the darn thing), and to get a development environment up and ready it took ages just to figure out the right one!

I really like the idea of having Desktop like applications on the Web but i’d also like to have them in my desktop. Most of these allows developing both for the Web and for the Desktop but Flash and Java might just have an edge on this one. Adobe AIR allows you to develop some pretty cool desktop apps and JAVA has been improving Swing with LaF.

To sum up, I like the fact that Javascript has been evolving at a fast pace but I still feel stranded by browser dependencies, I don’t like to have the source code exposed and I just think that Adobe’s offer is a better deal. ActionScript is a pretty decent language and the Flex framework offers us a lot of cool components. Add to that the AMF protocol with the Open Source Data Services and you have a very good solution for RIA development. What’s more you have a couple of 3D libraries,Thermo’s coming up ( pixel shaders ;) ) and we’ll get hardware acceleration!