JavaFX: Create Windows Native Installer and EXE with NetBeans 7.2
Duke Waving

With the release of Java 7 u6 and now Java 7 u7 and Java FX 2.2, you can create a Windows native installer and application. There are a couple of good guides out there, consider this the Joe Friday version. The steps that follow show how to setup NetBeans 7.2 to create Windows native installers and applications. Yes folks, turn your JavaFX application into an EXE!!!!

Note: The versions listed are required for this to work. However, newer versions should, of course, still work.

Initial Setup

Java 7 JDK

First, you need to install Java 7 u7 or later. This includes JavaFX 2.2 which is now just part of the JDK. No need to go into the installation steps, just a standard install in the default location is fine.

Java JDK 7

NetBeans 7.2

Next you will need to install NetBeans 7.2. I use the Java EE version, but the SE edition should work too.

NetBeans 7.2

Installation Software

To make the exe file, download and install Inno Setup 5. This makes an installer and creates an exe. To create an .msi installer use WiX.

Create a JavaFX Application in NetBeans

Of course, before we can create an installer for an app, we need an actual application. If you are just testing, the default JavaFX application works just fine. To create it, start NetBeans then choose File --> New Project --> JavaFX --> JavaFX Application. Select a Project Name and a directory location and you should be all set.

Note: For my example I used a sample app I created called TextViewer. In my source files you will see a references to that project.

Before proceeding, make sure you can build and run your application. This should ensure that you have a build.xml file and that everything is working correctly.

Configure NetBeans Ant Build File

Hooray! You have a JavaFX app and you are ready to package it for Windows. So to do that, we are gonna need to make a couple of configuration changes to the build.xml file.

Aside: Hey Mike. What is this build.xml file of which you speak? NetBeans uses Ant for all of its Java compiling and packaging tasks. Ant uses XML files for its configuration. So to make native packaging work, we need to make a few edits to some of these files. Typically, build.xml is the main configuration file for NetBeans' projects.

Adding a Build Target

The next step in the process is to add a build target for JavaFX to the build.xml file. Here is what the code looks like. We may refer back to this again later.


   1     <target name="-post-jfx-deploy">
   2        <fx:deploy width="${}" height="${}" 
   3                  nativeBundles="all"
   4                  outdir="${basedir}/${dist.dir}" outfile="${application.title}">
   5           <fx:application name="${application.title}" mainClass="${javafx.main.class}"/>
   6           <fx:resources>
   7               <fx:fileset dir="${basedir}/${dist.dir}" includes="TextViewer.jar"/>
   8           </fx:resources>
   9           <fx:info title="${application.title}" vendor="${application.vendor}"/>
  10       </fx:deploy>          
  11     </target>

To install the target for FX, follow these steps:

  1. Get the XML code for the JavaFX target here: fxtarget.xml. Copy the text to the clipboard.
  2. Open your NetBeans Project.
  3. Click on the Files tab. This should show all the files in your project. Open the build.xml file.
  4. Paste the code you copied on the line after the import tag.
  5. Next, add an XML namespace for the fx target. Add the following text to the project tag of the build.xml file: xmlns:fx=""
  6. Save the file.
  7. Click on the Projects tab in the upper left corner of NetBeans.
  8. Clean and Build the project.

You should now see some additional information about your build, similar to this:

Created dir: C:\Users\student\ora\javaone\java1-pub\packaging\native\TextViewer\dist
Detected JavaFX Ant API version 1.2
Launching <fx:jar> task from C:\Program Files\Java\jdk1.7.0_07\lib\ant-javafx.jar
Launching <fx:deploy> task from C:\Program Files\Java\jdk1.7.0_07\lib\ant-javafx.jar
Using base JDK at: C:\Program Files\Java\jdk1.7.0_07\jre
  Skip [MSI Bundler (WiX based)] due to [Can not find WiX tools (light.exe, candle.exe).]
Detected [iscc.exe] version 0.0 but version 5.0 is required.
  Skip [Exe Bundler (based on Inno Setup)] due to [Can not find Inno Setup 
  Compiler (iscc.exe).]
Creating app bundle: TextViewer in C:\Users\student\ora\javaone
Result application bundle: C:\Users\student\ora\javaone

The following section endeavors to fix those skip messages shown above.

Final Touches to build.xml

There are a couple of other changes you need to make to the build.xml file before your exe and installer will be built.

Enter your Application Name

Look at the build.xml file and in the fx:fileset tag, replace TextViewer.jar with the jar file name of your application.

Set the Application Title and Vendor

The final thing you must do is set the application title and vendor for the installer. The vendor name on Windows is used to determine what directory name your application is installed under in the applications folder. The title will of course be used to name the shortcut that launches your application. You have two choices for set these names, do only one of the following.

  1. Choice one, in build.xml edit the fx:info tag and replace ${application.title} and ${application.vendor} with the strings you wish to use for your application.
  2. Choice two, in the nbprojects directory, edit the file and file the application.title and application.vendor key and replace the values defined there with your title and vendor name.

With that, everything for NetBeans should be configured. Now go to the next section and setup your installer applications.

Configuring the Installer Apps

Add Inno Setup 5 to the Path

For Inno Setup 5 to create its installer bundle, it needs to be in the path. To check to see if it is in the path, open a Command Prompt window and type:
If the file is not found, then Inno Setup 5 is not in the system Path variable.

To set the path on Windows 7 select Start --> Computer --> System Properties --> Advanced System Properties --> Environment Variables then choose System Variables, Path, and then Edit. Enter the following to add Inno Setup 5 to the Path: C:\Program Files (x86)\Inno Setup 5;

Now typing iscc.exe should produce something like this:

This part of the build process should now be ready to go.

Add Wix to the Path

Just like Inno Setup, Wix needs to be in your system Path for NetBeans to be able to use it. Add the Wix bin directory C:\Program Files (x86)\WiX Toolset v3.6\bin to the path like you did for Inno Setup. To test to see if Wix is in the path, open a Command Prompt window and type:
If the file is found and you get help information like you did for iscc.exe, then you should be ready to go.

Building you Native App and Installer

With everything configured and ready to go, it is time to clean and build your application. Clean and build your project. When you do, you should notice the build process takes quite a few seconds longer as the native application files are created.

NetBeans builds a bundle directory under the code directory. All the native files and installer can be found here. The directory contains the compressed installer with a .exe and .msi extension. In addition, a runnable .exe with the JRE required for the Java app is included. For my test application, the bundle took about 217MG. The .msi file was 30MB and the .exe file was 47MB.

Run the installer to have your application installed natively. Your application should be installed in the start menu under the vendor name you set up earlier. You should be able to run your application just like any other Windows app!

In my testing, for Inno Setup 5 (.exe) the application was installed in the C:\Users\username\AppData\Local directory and takes up about 140MB of disk space. For the WiX installer (.msi) the application was installed in the C:\Program Files (x86)\TextViewer directory and takes 140MB.


NetBeans Build Error: The prefix "fx" for element "fx:deploy" is not bound.

This is caused by not defining an XML namespace for "fx". See the Adding a Build Target section above for details.

NetBeans Build Error: Main application jar is missing.

Problem: Both Inno Setup 5 and Wix are installed and in the path, but no exectuables are being built. Plus, I am getting error messages like the following:

  Skip [Windows Application Bundler] due to [Main application jar is missing.]
  Skip [MSI Bundler (WiX based)] due to [Main application jar is missing.]
  Skip [Exe Bundler (based on Inno Setup)] due to [Main application jar is missing.]

Solution: The .jar name of your application has not been added to the build.xml file. Make sure you have replaced TextViewer.jar with the name of your application.

Install Problem: The App installed under my user name for my laptop.

Solution: You have not set the application.title or application.vendor set in either the build.xml file or the nbproject/ file. See the Final Touches section above.


The following resources were used to created this page: