How to distribute a Java application as executable (.exe) file

One of the options how to distribute your Java application is to make the JAR file (Java archive). Every Java archive contains a manifest file which describes the rest of the files in the archive. These are typically class files, security information, etc.

The creation of Java archive is possible in the project tree in NetBeans IDE. Once you already created your project using NetBeans IDE, right-click the project name and select “Clean and Build”. Now the Java archive file will be created in the “dist” folder in the project directory. The dist folder might also contain a lib folder, which you would also need to include.

Java archives are portable across platforms which have the Java Runtime Environment (JRE) installed in it. JRE includes the language compiler, the library files and the Java Virtual Machine (JVM) in which java application executes. If you created a GUI application, double-click the file icon to launch the program, and JVM handles the creation of application’s window in an operating system environment. However, if you created a console application, it is necessary to open a command line in order to run a command similar to: java -jar archive.jar.

The creation of an executable (.exe) file

Running of a console application is rather awkward in the Windows environment. However, there is a possible to create an executable .exe file, which automatically open a command line window and run the application. There are several ways to create an executable file, however, using the built-in Windows IExpress application is the simplest of them all. Windows IExpress is located at C:\Windows\system32\iexpress.exe (replace “C” with whatever drive you have on your computer) and it is a tool that creates custom, self-installing and self-extracting files of applications. The procedure is as follows:

  1. On your computer running Windows, click Start, click Run, enter iexpress, and click OK. This starts the IExpress Wizard.
  2. On the Welcome to IExpress 2.0 page, select Create new Self Extraction Directive file and click Next.
  3. On the Package purpose page, select Extract files and run an installation command and click Next.
  4. On the Package title page, type a title of your application and click Next.
  5. On the Confirmation prompt page, select No prompt and click Next.
  6. On the License agreement page, select Do not display a license and click Next.
  7. On the Packaged files page, click Add and select the Java archive from the directory in which it resides (the name of archive must be no longer than 8 characters). When you finish, click Next.
  8. On the Install Program to Launch page, in the Install Program box, type command: cmd /K “java -jar archiv.jar”. The command opens the command line window and run the application.
  9. On the Show window page, select Default (recommended) and click Next.
  10. On the Finished message page, leave the No message and click Next.
  11. On the Package Name and Options page, enter the path and filename that you want for this application (e.g. myapp.exe). Check the box Hide File Extracting Process Animation from User and click Next.
  12. On the Configure restart page, select No restart and click Next.
  13. On the Save Self Extraction Directive page, select Don’t save, and click Next.
  14. On the Create package page, click Next. When the excutable file has been created, click Finish to exit.

The executable file will now be created and ready for distribution. However, it is still executable on computers have JRE installed only.

One thought on “How to distribute a Java application as executable (.exe) file

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>