How to make a runnable jar for an application that uses JavaFX without native installers


I have a application that worked just fine to be run with "java -jar blah.jar" after exporting as a runnable jar from Eclipse and letting it "Package required libraries into generated JAR".

I added some JavaFX code to pop up a web browser. Now it seems it is impossible to make a runnable jar that works across minor Java versions. When I export it as a runnable jar, it copies in jfxrt.jar that is specific to my minor version. If I run this jar using "java -jar blah.jar" for the exact matching java version (jdk1.7.0_17) then it works fine, but if I use one slightly newer (jdk1.7.0_45) then it fails to resolve swingx classes properly. So much for "write once run anywhere".

I tried to use the JavaFX ant tasks but I can't get the task to actually package up the dependent jars. This doesn't actually include the fx:resources jars in the jar it creates, like the magic eclipse "package required libraries into generated JAR" does perfectly:

<fx:jar destfile="${dist}/${dist.jar}"> 
        <fx:application id="BlahTesterApp" 

        <fileset dir="${build}"/> 

            <fx:fileset dir="${lib}" includes="**/*.jar" />

            <attribute name="Implementation-Vendor" value="My Team"/>
            <attribute name="Implementation-Title" value="Tester App"/> 

And seems to only be able to create "native bundles" which I don't want. I don't want to make users install an rpm or a deb when they used to just be able to run the darn jar.

I don't understand why Oracle had to introduce its own magical extra layer of deployment complexity here. Don't they want people to USE JavaFX?

4/16/2014 6:54:05 PM

JavaFX packaging alternatives

  1. Follow the e(fx)clipse tutorial for creating an executable jar file for a JavaFX application using Eclipse.
  2. The Oracle java packaging ant tasks and javafxpackager tool can create executable jars (described in the Oracle documentation as standalone applications). If you cannot generate such jars using the tools, then you are likely not using the tools correctly.
  3. Require a minimum version of Java 8, where jfxrt.jar (i.e. the JavaFX classes) is on the boot class path.
  4. Use a 3rd party build tool chain such as the JavaFX Maven plugin or the JavaFX Gradle plugin.

Alternative (1), e(fx)clipse packaging, is recommended for you since you are using Eclipse.


Never try to include Java platform libraries (such as jfxrt.jar) with your application. No guide you find on the internet should ever instruct you to do such a thing (due to the obvious incompatibility between minor version issues you outlined in your question). The only exception to this rule would be if you are building a self-contained, native installed application that doesn't rely on a pre-installed JRE (which you aren't).

12/5/2016 7:03:59 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow