NetBeans has a Packaging option for creating a "Native" application, i.e., a MyApp.exe file for Windows. The importance of this is you get a Windows executable the INCLUDES JRE, meaning that the ultimate user doesn't need to install Java or JRE on his/her machine to run the application.
This sounds wonderful, but the documentation is not at all clear about how to make it work, at least not to me. Here's what I've learned.
First, for this to work you have to have Inno Setup 5 or higher installed on you development computer. Apparently, NetBeans creates an Inno .iss file and runs it.
To understand it better I made a NetBeans projects for the Inno AnagramGame example. To enable the Native packaging option, first select the Project in NetBeans , right-click and select Properties|Deployment. Check the Native packaging box. This causes the EXE option to be placed on the NetBeans Packaging menu. I.e., Select the Project, right-click and click on Package As. Clicking EXE Installer launches the process of building the "package."
Building the installer takes a LONG time because it has to accumulate all the necessary pieces of the JRE and incorporate into the package. This also makes the installer BIG. Even for the smallest Java program it will be about 35 Mb.
After the Native packaging of some app, for example AnagramGame2, you will find the following in the NetBeans project folder:
C:UsersEd SowellDocumentsNetBeansProjectsAnagramGame2distanagrams.jar
and
C:UsersEd SowellDocumentsNetBeansProjectsAnagramGame2distundlesAnagramGame2-1.0.exe
Anagrams.jar is the Java archive file for the AnagramGame2 app. IF YOU HAVE JAVA INSTALLED, this will actually run the project by double clicking. However, if you move it to another computer WITHOUT Java or JRE installed, it will not be executable. The reason is the jar file does NOT incorporate the JRE. It took me long time to recognize this.
Now, you might be thinking AnagramGame2-1.0.exe is the Native executable for the app but, nay, it is not. It is in fact the installer, another thing that took me a long time to recognize.
So, where is the fabled Windows Native app file? The answer is it is nowhere, yet. In order to get it YOU MUST RUN THE INSTALLER! After running it you will find the much wanted EXE in, of all places, C:UsersEd SowellAppDataLocalAnagramGame2:
C:UsersEd SowellAppDataLocalAnagramGame2AnagramGame2.exe
Also, with the appropriate options selected, the app name will appear on the Windows Start menu and desktop.
So, to distribute the Windows Native application you have to:
- Create a NetBeans project.
- Do a Clean build of the project
- To enable the Native packaging option for the project
- Do a Package as|Native installer
- Distribute the installer, in this example it is AnagramGame2-1.0.exe
- Your user then runs the installer. Afterwards, he/she runs the app from the Start menu or double clicking the desktop icon.
There's still a lot I don't understand about the proper use of this NetBeans/Inno Setup process. There are some small mysteries, such as why it hides the location of the end product in User AppData Local. Who would have thought to look there? And why does it call the Installer AnagramGame2-1.0.exe instead of something like setupAnagramGame2.exe? But here's the biggest problem I've yet to solve: How does one install ancillary files needed by the app? Or get needed data out of an INI file? If the .iss that is built and used in the NetBeans process were made available it could be edited, but so far I've not been able to find it. My guess is it gets deleted. Short of that, the only thing I can think of is to write another .iss file to do that work. Unfortunately than means the user has to download and run two installers!