• Aug
    • 01
    • 2013

JavaFX on iOS using RoboVM and Maven

Posted by In JavaFX, RoboVM

A bit of background

Oracle have open sourced JavaFX and included in it code that allows JavaFX to run on iOS. The only problem is they haven’t provided a way to actually run Java on iOS, which, as you can imagine, is something of a necessary first step. It’s a little bit like giving us an awesome new type of high speed rail engine – we just have to build the train that the engine goes in, and lay the tracks, and build the stations, and provide the fuel, and …

For reasons many of us don’t understand and certainly don’t agree with, Oracle have decided that the huge, complex and difficult task of getting a Java VM running on iOS is something the community should do. While there have been many loud and, let’s say, “passionate” responses and objections to this, there’s not likely to be any change on this from Oracle anytime soon.

So the community are doing what they can. Niklas Therning, from Trillian AB, has been working hard on a Java VM that runs on iOS and has released a very early access version of RoboVM. This is not the only Java iOS option but it is the one that is most ready to use with JavaFX. RoboVM compiles Java bytecode into native code that can be run on iOS. It is based on the Android Java Runtime so it doesn’t support all Java features but it comes close enough for our purposes.

Unfortunately the version of JavaFX that has been open sourced runs only on Java8 (not yet released) and RoboVM currently only runs on Java7.  To solve this part of the problem Danno Ferrin has created a backport of the Java8 version of JavaFX to run on Java7. In turn, I’ve taken the awesome work done by Niklas and Danno and combined this into a Maven plugin for RoboVM, that has special support for JavaFX in it to ease the developer workflow.

The end result has just been released and below I give you the (hopefully simple) steps to get your own JavaFX app running on iOS!

A word of warning: this is at best an alpha release! It is slow, it is buggy and the process is still clunky in places. The good news however is that there is plenty of room for things to be optimised, cleaned up and improved. Things can only get better – so don’t judge the platform by what you see now, judge the potential.

Business Time

Before getting started:

You need to have JavaFX on your classpath, so use the JavaFX Maven plugin to do this by running the following command line:

  • mvn com.zenjava:javafx-maven-plugin:2.0:fix-classpath

On mac you will probably have to run this using sudo.

Then simply check out the sample JavaFX RoboVM app:

And from the command line run your choice of:

  • mvn robovm:iphone-sim  (runs the app in the iphone simulator ) 
  • mvn robovm:ipad-sim  (runs the app in the ipad simulator)
  • mvn robovm:ios-device  (runs the app on whatever iOS device is plugged in)

That’s it!

Note: the sample app will only run on the latest iOS so make sure your device is fully updated. This is an aspect of the sample app, not RoboVM, eventually we will provide docco on how to run on older versions of iOS.

Currently there’s no automated way to generate an app bundle for the app store. The focus is on improving the performance and functionality at this stage, and commands for building App Store bundles will be added.

A little more detail

The sample app is a very simple JavaFX “Hello World” app that is setup to build and run with RoboVM. It’s designed to be a kickstarter template – take this code, copy it into your own project, and then expand on it to build whatever you want.

RoboVMSampleJFXApp.java is the entry point for the JavaFX app. From here down you can insert your own JavaFX app and make whatever you want.  In theory you should be able to more or less ignore the fact that you are in a iOS app and just build a JavaFX app. In practice, especially in this alpha release, there will be areas where things fall down but you should be able to do most of the standard JavaFX stuff.

RoboVMJFXLauncher.java is a special wrapper for your App and is the main entry point for RoboVM. It simply sets up your JavaFX application so it can run on iOS. Take a straight copy and paste of this into your own project and just change the name to be whatever you want, etc. Future versions of the Maven plugin will likely generate this class for you so you won’t have to include it, but for now just copy it in.

The project’s POM has a couple of RoboVM specifics but it is not too bad. The RoboVM Maven plugin is included and configured, and there are some dependencies onto the RoboVM runtime libraries, which you need at this stage. These dependencies may not be necessary in future versions of the plugin if we can find a way to cleanly hide them.

There are many configuration options for the RoboVM Maven plugin, letting you do things like modify your plists or set the signing agent, etc. Currently these are not well documented and you’ll have to work off the code. Documentation is on the todo list.

Where to from here

No doubt there will be many teething problems and issues. Be gentle with it, feedback is probably best first discussed on the openjfx mailing lists: http://mail.openjdk.java.net/mailman/listinfo/openjfx-dev as it will be hard at first to know what is a JavaFX issues and what is a RoboVM issue. It will be good for the Oracle JavaFX guys to see what problems are coming up anyway.

As I mentioned at the start, this is a rough, early-access, alpha release. We know it is not performant, we know it has rendering and layout issues, we know it’s a long way from perfect. Things will improve massively from here. How fast it improves depends on how much time those working on it can contribute – this is currently a completely unfunded community effort by volunteers in their free time.

If you want a robust, production-ready version of all this then you have two choices:

  • 1. Wait for it to happen
  • 2. Contribute – either time/code or talk to Niklas about how you can help sponsor his work financially

5 Comments

  • Solerman
    August 12, 2013

    RoboVM isn’t the only option, there is also Avian which can do java 6 as well

  • August 18, 2013

    Hi

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

    is not working, is trying to work with java 1.6 , bundle with mac, instead the current configurated and active from oracle.

    running with -X at the beginning shows:

    Java version: 1.6.0_51, vendor: Apple Inc.
    Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

    but the systems uses oracle jdk 1.7, even maven 3.1.0 (yes a the new version)

    mvn -version shows:

    Apache Maven 3.1.0 (893ca28a1da9d5f51ac03827af98bb730128f9f2; 2013-06-28 04:15:32+0200)
    Maven home: /opt/local/share/java/maven-devel
    Java version: 1.7.0_25, vendor: Oracle Corporation
    Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre
    Default locale: en_US, platform encoding: UTF-8
    OS name: “mac os x”, version: “10.8.4″, arch: “x86_64″, family: “mac”

    Regards

Leave a Comment