Dustin Marx is a software developer who enjoys identifying and using the correct tool for the job. In addition to writing software and writing a blog on software development, Dustin occasionally presents at conferences and writes articles. Dustin is a DZone MVB and is not an employee of DZone and has posted 235 posts at DZone. You can read more from them at their website. View Full User Profile

Native Java Packaging with NetBeans 7.4

  • submit to reddit

One of the new features of NetBeans 7.4 that made the "NetBeans 74 NewAndNoteworthy" page is "Native Packaging," which is described on that page as "JavaSE projects now support creation of native bundles taking use of the native packaging technology provided by JavaFX."

I will use a very simple example to demonstrate this native packaging functionality in NetBeans 7.4. The next code listing is for this enhanced Hello World example.


package dustin.examples;

import static java.lang.System.out;

 * Slightly enhanced "Hello World" example.
 * @author Dustin
public class EnhancedHelloWorld
    * Main function.
    * @param args the command line arguments; name being addressed, if any.
   public static void main(String[] args)
      final String addresseeName = args.length > 0 ? args[0] : "World";
      out.println("Hello, " + addresseeName);

The next image shows this same code in the NetBeans 7.4 source code editor.

To use the Native Packaging feature, I can right-click on the project and select Properties as shown in the next image.

Clicking on "Properties" leads to the appearance of the "Project Properties" window. This window, as shown in the next screen snapshot, allows the developer to expand the "Build", select "Deployment", and check the box next to the label "Enable Native Packaging Actions in Project Menu." Selecting this option configures NetBeans 7.4 to support native packaging for that NetBeans project.

With NetBeans 7.4 native packaging enabled, I can now right-click on the project and have a new option called "Package as" available. When I select that "Package as" option, I see the following choices: "All Artifacts", "All Installers", "Image Only", "EXE Installer", and "MSI Installer". Note that my NetBeans 7.4 IDE is running on a Windows machine, so the EXE and MSI installers make sense. Sections 6.4.1 and 6.4.2 of the Deploying JavaFX Applications document cover the EXE and MSI installer packages respectively.

When I select EXE as the installer package, I see it processing the native packaging per the message in the bottom right corner of the IDE. This is shown in the next screen snapshot.

The first time I tried this, I ran into an error reported by NetBeans with the message: "JavaFX native packager requires external Inno Setup 5+ tools installed and included on PATH to create EXE installer. See http://www.jrsoftware.org/". Going to the referenced Jordan Russell Software site allows me to download Inno Setup 5.5.4 (isetup-5.5.4.exe). In my case, I downloaded the self-extracting EXE and ran it. I then added the full path to the directory into which Inno Setup 5.5.4 was installed to my PATH environmental variable and restarted NetBeans 7.4.

With Inno Setup installed on my system, the Inno Setup 5.5.4 installer compiler runs when NetBeans's EXE native packaging is selected. When NetBeans and Inno Setup complete, a relatively large EXE file exists in the project's directory as shown in the next screen snapshot.

I can run this executable, of course, by simply typing its name at the command prompt. The next screen snapshot demonstrates that running this executable leads to a popup window requesting approval to install the Java application.

When the "Install" button is clicked, the installation begins and this is demonstrated in the next screen snapshot.

The executable installer installs the Java application as another executable. In this case, this application is installed in C:\Users\Dustin\AppData\Local\EnhancedHelloWorld as shown in the next screen snapshot.

The generated directory shown in the screen snapshot above includes a "runtime" directory with the necessary JRE to run this application even on machines that don't have a JRE installed. The Java application itself is stored as a JAR in the "app" directory. Both of these subdirectories are shown in the next two screen snapshots.

The generated directory includes two .exe files. One is EnhancedHelloWorld.exe, which is the Java application executable. The other .exe file is unins000.exe. Running this latter .exe file cleanly uninstalls the application from the computer.

The next screen snapshot shows that I am able to start the application from my Window Start in addition to clicking on the generated executable file.

Although the Java code sample I started with can be built as an executable application using NetBeans 7.4 as shown in this post, it is far more interesting to use a Java application with a user interface. For example, one could build an executable application with NetBeans 7.4 based on the Java class HelloWorldSwing.

My examples in this post have been entirely Java SE (no JavaFX), but have taken advantage of NetBeans 7.4's support of native packaging via mechanisms generated for JavaFX deployments. Therefore it's not surprising that the JavaFX documentation on Self-Contained Application Packaging is useful for understanding the options available. Native packaging with NetBeans 7.4 is also demonstrated in Native Packaging in NetBeans IDE.

Published at DZone with permission of Dustin Marx, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Raging Infernoz replied on Mon, 2013/12/02 - 9:15pm

I really don't give a fly f' for anything Ant in NetBeans because it was so klunky and brittle, that I got p'd off, migrated all my projects to Maven, and refuse to do any more Ant projects in NetBeans now!

Where is the integrated Maven support for this?

When the f' are the NetBeans team going to stop p'ing around with Ant, migrate the features to Maven, and encourage all the plugin authors to support Maven properly!?

Ed Hillmann replied on Wed, 2013/12/04 - 5:47am in response to: Raging Infernoz

Actually, NetBeans has had full support for Maven for quite some time now.  I have been using it full-time for at least the last five years, it's quite mature and reliable.  I suggest you take a deep breath, find a happy place and take a look for yourself, instead of ranting about one example.

It will support any Maven project, regardless of whether it was created by NetBeans as well.

Lots of people still use Ant.  Not me personally, but many of the NetBeans developers continue to use it because their build scripts are quite complex and performs a lot of tasks for them.  I think it's a credit to NetBeans that they can support a wide range of development tools.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.