Bundling a JRE with Launch4j: A Step-by-Step Guide
Launch4j is a powerful tool for bundling Java applications into self-contained executables. One of its key features is the ability to include a Java Runtime Environment (JRE) with the executable, providing standalone execution on machines that do not have a JRE installed.
To bundle a JRE with Launch4j, follow these steps:
1. Obtain a Compact, Portable JRE
- Download the JRE installer package from Oracle.
- Unzip the installer package to extract the JRE directory.
- Copy the JRE directory to a convenient location.
2. Structure Your Application
-
Create a container folder. This will hold your application and JRE.
-
Create a jre subfolder within the container folder.
-
Copy the extracted JRE directory into the jre subfolder. This should include subfolders named bin (containing java.exe) and lib.
-
Add your application files to a separate subfolder within the container folder, such as bin.
3. Configure Launch4j
- Open your Launch4j configuration XML file.
- In the element, specify the path to the JRE directory. The path should be relative to the location of the executable and point to one folder before the java.exe file. For example:
<jre>
<path>../jre</path>
<opt>-DgvSIG.confDir=../cfg</opt>
</jre>
Copy after login
-
Optional: Configure additional JRE options, such as memory settings, using the element.
4. Package Your Application
- Build your Launch4j executable by running the configuration file. The resulting executable will include the JRE and your application.
By following these steps, you can bundle a JRE with your Launch4j application, ensuring that it can be executed on any machine, regardless of its JRE installation status.
The above is the detailed content of How to Bundle a JRE with Launch4j for Standalone Execution?. For more information, please follow other related articles on the PHP Chinese website!