What is the best way to deploy a JavaFX application, create JARs and standalone applications, and native installers

I am using IntelliJ IDEA and I have a JavaFX application ready for deployment. The problem is that when I create the JAR file, it does not start, when I run it on the command line, I get an exception, an FXMLLoadException, although the project works fine in my IDE.

Ant tasks end in errors, after 15 minutes of work I really don’t understand what the problem is.

So my question is: what are the right steps to properly deploy a JavaFX application, any tutorial or guide would be welcome.

+7
java intellij-idea executable-jar javafx ant
source share
3 answers

A Java application can be packaged in various ways. Read the Java Packaging Overview to find all about it. One of the packages is a self-contained Java application .

There are various ways to create these packages:

  • Use the javapackager tools that come with your JDK
  • JavaFX Ant Tasks
  • JavaFX Maven plugin for maven project

A standalone application is a way in which your application can be packaged and platform specific. Package contains:

  • Application package
  • Private copy of JRE

A list of available packages can be found here .

Let's look at the tools we have and how to use them:

JavaPackager Tool

The JavaPackager tool is the easiest tool and allows 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.

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

JavaFX Ant Tasks

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

A set of examples of using Ant scripts for your project can be found here .

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

JavaFX Maven Plugin

JavaFX Maven Plugin uses the use of the java application for packaging on the maven platform. You can pack it into a maven-based java application by adding a plugin to the project.

This plugin is IMHO if easiest use of the three. This is a very well written, understandable tool and extensive documentation.

JavaFX Gradle Plugin

The JavaFX Gradle Plugin is also owned by the maven plugin author. It has all the functions that the maven plugin has, but for Gradle :)

Further reading:

+17
source share

Oracle has an extensive packaging guide on its website for JavaFX 2 and JavaFX 8 .

If you need help with your specific problem, send the code and the stack line of the error you will receive.

+1
source share

If you are using Maven, another very smart approach is to use maven-shade-plugin ( link ). It creates one big fat jar with all the addictions inside which you can execute directly without any additional actions. You can use this in conjunction with javafx-maven-plugin . I also tried different approaches and played for a long time, and this solution was the only one that really works. In addition, it was easy to configure.

Here is what you need to add to your pom.xml:

 <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.1.1</version> <configuration> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>your.package.name.Main</mainClass> </transformer> </transformers> </configuration> </execution> </executions> </plugin> <plugin> <groupId>com.zenjava</groupId> <artifactId>javafx-maven-plugin</artifactId> <version>8.8.3</version> <configuration> <mainClass>your.package.name.Main</mainClass> </configuration> </plugin> </plugins> </build> 

Change the name of your package inside the mainClass for the shadow, as well as the javaFx plugin, and you're done. Now you can create your application, as always, using the mvn package .

0
source share

All Articles