What is the best way to deploy JavaFX application, create JAR and self-contained applications and native installers

Jean-Baptiste-B picture Jean-Baptiste-B · May 10, 2015 · Viewed 21k times · Source

I'm using IntelliJ IDEA, and I have my JavaFX application ready for deployment. The problem is that when I generate the JAR file, it won't run, when I run it in the command line, I get an Exception, FXMLLoadException, although the project is working perfectly in my IDE.

Ant tasks end with errors, after 15 minutes of building, I really don't understand what's the problem exactly.

So my question what are the right steps to deploy a JavaFX application the right way, any tutorial or guide will be welcome.

Answer

ItachiUchiha picture ItachiUchiha · May 11, 2015

A Java application can be packaged in various ways. Please go through Java Packaging Overview to find everything about it. One of the packaging is a self-contained Java application.

There are different ways to create these packages :

  • Use the javapackager tools that comes with your JDK
  • JavaFX Ant Tasks
  • JavaFX Maven Plugin for a maven project

Self-contained application is one the ways how your application can be packaged and is platform specific. The bundle contains :

  • The application package
  • A private copy of the JRE

A list of available bundles can be found here.

Let us check out the various tools available at our disposal and how to use them:

JavaPackager Tool

JavaPackager Tool is the most basic tool and helps you to compile, package, sign, and deploy your Java(FX) applications, without writing any additional scripts. The javapackager.jar file is located in the bin directory of the JDK installation.

The list of commands, that can be used with it is available here.

JavaFX Ant Tasks

JavaFX Ant Tasks helps you package your application by just creating a build.xml file for your project.

A set of examples on how to use ant scripts for your project can be found here.

The list of commands that can be used for with it is available here.

JavaFX Maven Plugin

JavaFX Maven Plugin leverages the usage of packaging java application to the maven platform. You can use it to package your maven based java application by adding a plugin to the project.

This plugin IMHO, if the easiest to use out of the three. It is a very nicely written, easy to understand tool and has extensive documentation.

JavaFX Gradle Plugin

JavaFX Gradle Plugin is also from the author of the maven plugin. It has all the features that the maven plugin has, but for Gradle :)

Further Reading :