In early November of 2011, I posted the following message on a thread related to Maven and JavaFX 2.0:
As a long time Maven user, I started looking into this issue. I thought I had a basic solution using shade. But, then, I ran into an UnsatisfiedLinkError against libmat.dylib. I found libmat.jnilib, but no libmat.dylib.
So I examined my application's manifest.mf, and discovered that the Main-Class attributed detailed 'not' my main class but a JavaFX-generated Main.class, coupled with Main$1.class and NoJavaFXFallback.class. I guess Main.class, generated by one of the many JavaFX ant tasks, loads the native libraries and my 'main' class. Oracle should provide the source for this code generation. Because requiring Ant, Netbeans and code generation to develop JavaFX 2.0 apps is a nonstarter.
I worked around this issue, but at the expense of an additional Maven artifact - the Netbeans generated application code calling my application. In other words, I had no direct control over my own main application code. Instead, I had to have Oracle-generated code invoke my application code.
Now, I haven't thought about this issue for nearly 2 months. But as a long time Swing developer, a direct dependency on Oracle Ant scripts and Netbeans is unacceptable. Have I misunderstood this dependency? If not, is this dependency forever or temporary?
Thanks in advance for any comments.
I think the JavaFX-generated Main.class you are referring to is also known as the "JavaFX launcher".
A description of what the launcher does is here (http://docs.oracle.com/javafx/2.0/deployment/packager001.htm):
"By default, the Create JAR command also inserts the JavaFX Launcher into the JAR archive. The JavaFX Launcher is responsible for locating the installed JavaFX Runtime and invoking the main application class using this Runtime. The JavaFX Launcher also enables the JAR file to be run by double-clicking the file. Use the -noembedlauncher option to keep the launcher from being embedded."
So, it seems the use of the launcher is optional. If you don't need or want the extra functionality the launcher provides, then you don't need to include it in your package.
To run your application without the launcher, place the jfxrt.jar file on your classpath (e.g. with the java -cp <jfxrt.jar path> -jar your jar file). As long a correct version of JavaFX and Java is installed on your machine, I believe your application should run fine. If you are just executing the class files locally for development purposes, you don't need to bother with the jar step and can just use something like java -cp <jfxrt.jar path>;. com.app.AppMain (see Command-line/Runtime.exec() JavaFX app?
To build your application, you don't need to use NetBeans or Ant scripts, for example I build apps for development using compilation and packaging tools built into intellij Idea (with jfxrt.jar added as a library to the project). I have also used modified versions of the maven script here http://truezip.schlichtherle.de/2011/10/04/updated-maven-archetype-for-javafx-2-0-in-scala (note that this example uses the optional ant tasks to get more functionality). Additionally, I have done some command line based development using the javafxpackager tool (see here How to compile JavaFX 2.0 app with javac.exe from command prompt? for a sample batch build file).
If you use the ant scripts, the javafxpackager tool, or netbeans (which just relies on the ant scripts for build) then you do have more packaging options available then if you don't use those scripts (for example binary compilation of css, inclusion of the javafx launcher, etc), but they are only desirable, not necessary, tools for development of javafx projects.
If you are interested, there are also threads on maven development on the open-jfx mailing list (http://mail.openjdk.java.net/pipermail/openjfx-dev/2011-December/thread.html, http://mail.openjdk.java.net/mailman/listinfo/openjfx-dev), you can post there to discuss the launcher or maven support if you wish.