How to deploy java application and to create setup for windows

Admin
By -
0

 

Welcome to BasanzieTech!

In this article, I will guide you step by step on how to deploy your Java application and create a Windows setup (.exe) installer that includes all the necessary dependencies.

Back in 2015, while studying at Ruaha Catholic University, I developed a simple Java application called Mchepuko. Since then, I have created several small Java projects using different IDEs. During my early programming days, I mainly used Eclipse to develop and run my applications directly from the editor.

However, one day, a question came to my mind:

What if a client requests software? How can I deploy my Java application so that it runs smoothly on their computer without requiring them to install additional software?

As we know, Java applications depend on the Java Runtime Environment (JRE) to run. For many users, installing separate components such as the JDK or JRE can be confusing. Therefore, I wanted a way to package my application together with the JRE to simplify the installation process, just like any other Windows software.

After several days of researching online, I finally discovered a practical solution that worked perfectly. Since then, I have used this approach to create standalone Windows installers containing both the Java application and the embedded JRE.

Today, I have decided to share this method with other Java developers who are looking for a simple and professional way to deploy their desktop applications.

In the following sections, I will explain how to package your Java source code into a Windows setup file with an embedded JRE, step by step.

Before we begin, I assume that you already have a basic understanding of Java and some experience using an IDE such as Eclipse, NetBeans, or IntelliJ IDEA.

Step 1: Test and Export Your Java Application as a Runnable JAR File

Before creating your setup file, make sure your Java application runs correctly and has been thoroughly tested. This will help you avoid rebuilding the project later because of minor errors or missing components.

Once everything is working properly, follow these steps in Eclipse:

  1. Go to the top menu and click File → Export.

  2. When the Export dialog box appears, expand the Java folder.

  3. Select Runnable JAR File, then click Next.

This process allows you to package your project into a single executable .jar file that can run outside the Eclipse development environment.


Step 2: Configure and Export the Runnable JAR File

After selecting Runnable JAR File and clicking Next, the export configuration dialog will appear.

In this dialog, follow these steps:

  1. Under Launch configuration, select the project you want to deploy.

  2. In the Export destination field, click Browse and choose the folder where you want to save the exported JAR file.

  3. Under Library handling, select the option “Extract required libraries into generated JAR”.

  4. Finally, click the Finish button.

Once the export process is complete, your Runnable JAR file will be generated and saved in the folder you selected.

(Refer to the screenshot below for guidance.)


Step 3: Convert the JAR File to an Executable (.exe) Using Launch4j

At this stage, you should have your Runnable JAR file ready. Run it to verify that everything works as expected. Once you have confirmed that the application runs correctly, you can proceed to convert the JAR file into a Windows executable (.exe).

For this process, you will need two tools:

  • Launch4j: Used to convert your .jar file into a .exe file.

  • Smart Install Maker: Used later to create a professional Windows installer.

Let’s begin with Launch4j.

After opening Launch4j, a configuration window will appear. Follow these steps to configure it:

1. Basic Tab

  1. Specify the Output file location where your .exe file will be saved.

  2. Select the .jar file you want to convert.

  3. Optionally, add an application icon if you have one.

2. JRE Tab

  1. In the Bundled JRE path field, enter the exact directory path where your JRE will be located.

  2. This path tells your application where to find the Java Runtime Environment when it starts.

  3. Note: You will use the same path later when creating the installer with Smart Install Maker.

After filling in all the required fields, click the Build Wrapper button.

Launch4j will then generate your .exe file, allowing you to launch your Java application through a Windows executable.

(Refer to the screenshot below for guidance.)


Step 4: Create a Windows Setup File Using Smart Install Maker

At this stage, you have a .exe application that can run on Windows. However, it may not work yet because the JRE (Java Runtime Environment) is not available at the path you configured earlier in Launch4j.

To resolve this issue, we will use Smart Install Maker to create a Windows setup (.exe) installer that bundles your application together with the JRE. During installation, the JRE will be placed in the exact directory specified in Launch4j, allowing your application to run on computers without requiring users to install Java separately.

Before proceeding, follow these preparation steps:

  1. Create a new folder on your computer.

  2. Copy the .exe application you generated using Launch4j into the folder.

  3. Copy the JRE folder into the same folder. I recommend using the 32-bit JRE version if compatibility with both 32-bit and 64-bit Windows systems is required.

Your folder should now contain the following two items:

  1. The .exe application file.

  2. The JRE folder.

(Refer to the screenshot below for an example of the prepared folder structure.)

Once you have completed these steps, open Smart Install Maker to begin creating your setup file. In the next step, you will configure the installer to include both your application and the JRE, allowing users to install and run your software without manually installing Java.


Step 5: Configure Smart Install Maker to Build the Setup File

The screenshot below demonstrates how to use Smart Install Maker to configure and build your Windows setup file.

i. Under the “General” Tab

Enter the basic information about your application, including:

  • Product Name: The name of your software, for example, Mchepuko.

  • Version: The version number of your software, such as 1.0.

  • Company: The name of your organization or developer.

  • Website / Copyright: Optional fields where you can provide additional information about your application.

This information will appear in your installer, helping identify your software and giving it a more professional appearance.

(Refer to the screenshot below for guidance.)


ii. Under the “Files” Tab

In this section, you will add the files and folders that need to be included in your installer.

  • Click Add Folder and select the folder you created earlier, which contains both the .exe application and the JRE folder.

  • This ensures that both your application and the JRE are packaged together during the setup creation process and installed in the appropriate location on the user's computer.

(Refer to the screenshot below for visual guidance.)


iii. Under the “Requirements” Tab

In this section, you can specify the minimum Windows version supported by your application.

For example, you can select Windows 7 or a newer version, depending on your target users.

This setting helps ensure that your installer runs only on compatible systems and reduces installation problems on unsupported Windows versions.

iv. Under the “Dialogs” Tab

This section allows you to customize the installation process and configure important settings for your application.

  1. Destination Path: Specify the installation directory for your application. Make sure the JRE installation path matches the path you configured in Launch4j.

    For example:

    • If the JRE path configured in Launch4j is C:\Program Files\APS\jre

    • Set the destination path in Smart Install Maker to C:\Program Files\APS

  2. License Agreement: You can attach a license file if you want users to accept the terms and conditions before installing your application.

  3. Password Protection: Optionally, set a password if you want to restrict access to the installer.

  4. Enforce Path: Finally, select the “Enforce Path” checkbox to prevent users from changing the default installation location during setup.

(Refer to the screenshot below for the correct configuration.)


v. Build the Installer

After completing all the required information and configuration settings in Smart Install Maker, click the “Build Installer” button. The software will generate a Windows setup (.exe) file that:

  1. Installs your application on the specified Windows operating system.

  2. Includes the embedded JRE, so users do not need to install the JDK or JRE separately.

  3. Allows your application to run smoothly after installation.

Thank you

Post a Comment

0 Comments

Post a Comment (0)
3/related/default