Native Java Packaging with NetBeans 7.4

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.
 
 
 
 
EnhancedHelloWorld.java

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.

enhancedHelloWorldCodeInNetBeans74

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

rightClickNb74ProjectSelectProperties

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.

projectPropertiesNetBeans74

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.

netbeans74BuildingNativeExeHelloWorld

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.

dir_b_showsNetBeans74AppWithInno5Setup

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.

enhancedHelloWorldInnoSetupReadyToInstall

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

SetupEnhancedHelloWorldInstalling

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.

generatedEnhancedHelloWorldApplication

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.

generatedEnhancedHelloWorldApplicationJreDirectory

generatedEnhancedHelloWorldApplicationAppDirectory

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.

enhancedHelloWorldFromWindowsStart

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.
 

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

Leave a Reply


9 + = sixteen



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close