English English

Deployment of Java Applications as an installable application - JavaFX

You will learn here how to distribute your Java application (with JavaFX) to Windows and Mac computers. An installable Java application can be created directly from your IDE software.

Firstly, we will see how to create a distributable Java application for Windows. An exe file will be created, that installs your application and adds a short cut for the menu of your operating system.

On Windows

This part of the tutorial is done in a Netbeans Ant JavaFX (not Maven) project.

1. You have to add title and icon for your application

Please check if you did set title and icon for your Java application. Application icon is saved in the folder "src" of your project.

Add the following code in the method "start()" in your MainFXClass:

stage.setTitle("My APP title");
Image icon = new Image(getClass().getResourceAsStream("application_icon.png"));


2. You have to add also your application logo as an ico file and configure the deployment settings.

This can be done in the project properties in Netbeans.

In the tab "Projects": Do a right click on your project name -> Click on "Properties" -> Change to "Build" -> Go to "Deployment" -> Click on button "Edit" next to "icons and splash image". Add the full path to your ico file (your application logo) in the fields "WebStart Icon" and "Native Package Icon".

Go back to the open window "Project Properties":

  • Select "Compress jar" and "Enable native packaging" in the menu point ("Build" -> "Packing")
  • Select "Install permanently" and other checkboxes ("Add desktop shortcut", "Add Start Menu shortcut", "Allow to run with no internet connection") on the same row in tab "Deployment"


3. Change to your project window to the tab "Files". There you can find the file build.xml

Please add the following to the file build.xml:

<target name="-post-jfx-deploy">
        <fx:deploy verbose="true" nativeBundler="exe" outdir="${basedir}/${dist.dir}" outfile="${application.title}">
            <fx:application name="${application.title}" mainClass="${javafx.main.class}"/>
                <fx:fileset dir="${basedir}/${dist.dir}">
                    <include name="*.jar" />
                    <include name="lib/*.jar" />
            <fx:info title="${application.title}" vendor="${application.vendor}"/>
                <fx:icon href="/${basedir}/application.ico"></fx:icon>
            <fx:preferences shortcut="true"/>

Save this file.

4. Create the EXE installer

Do a Right click on your project name and click on "Package as" -> "EXE installer". An exe file will be created, which is your distributable application. This exe file installs your application.

Check the output for the path where you can find this exe installer file (it looks something like this):

Installer (.exe) saved to: C:\Users\MYUSER\Documents\Desktop_Java_Apps\MY_JAVA_APPLICATION\dist\bundles


On Mac

Do the same as mentioned above except point 4. Build your project to create your application as a jar file. Go the folder "dist", where you can find your jar file.

You can create an app file with the program "appbundler". You can download "appbundler" on: https://github.com/ome/appbundler

The mac application can be created only on a mac. Add the appbundler which is a jar file and to the folder "lib" in your project folder.

Add the following code to your build.xml.

<taskdef name="bundleapp"
         classpath="lib/appbundler-1.1.jar" />

You have to add your Java environment settings to distribute your application on the Apple store.

Please create a .bashrc file with the following content:

export JAVA_HOME=`/usr/libexec/java_home`

Add the following also to your build.xml - before the tag "taskdef":

<property environment="env" />

In the same file build.xml - Add this code after the tag "taskdef":

<target name="bundle-buttonDemo">
    <bundleapp outputdirectory="dist"
        name="My Application"
        displayname="My Application"
        <runtime dir="${env.JAVA_HOME}" />
        <classpath file="dist/MyApplication.jar" />

You have to sign your application before you can distribute it. Use the program "codesign" to sign your application file (.app file - Here: "MyApplication.app").

An example command of this program "codesign":

codesign -s "Developer ID Application: MYCOMMONNAMECERTIFICATE" MyApplication.app

More information about on how to sign a mac application: https://developer.apple.com/library/archive/documentation/Security/Conceptual/CodeSigningGuide/Procedures/Procedures.html

Please check also the developer website "developer.apple.com" to know more what you need (e.g.: distribution certificate) before you can submit an application to the Apple store.

We use cookies on our website. They are essential for the operation of the site