Make writing a habit together! This is my first day to participate in the “Gold Digging Day New Plan · April More text challenge”, click to see the details of the activity
preface
According to the public number of actual operation verification, real and effective, in case of need, Java packaging. Exe file execution, lightning protection, avoid stepping on the pit, we follow the steps of the problem is not big.
The preparatory work
- A normal no bug JAR package (network disk provided a small game jar package).
- Exe4j, a tool to convert a JAR into an EXE.
- Inno setup, a tool that combines dependencies with exe as an installer.
Link: pan.baidu.com/s/1uOUzMiHe… Extraction code: 8888
Positive start
1. Download and install Exe4J and open it
2. Click Next and select “JAR in EXE”
3. Click Next to customize the app name and output path
4. Click next
- Select whether the program runs on a GUI interface or a console (GUI is selected here).
- Custom generated. Exe application name.
- Set. Exe logo, can not upload (must be. Ico file, other files can not be identified, and will lead to the packaging error, you can not set this item).
- Set to 32-bit or 64-bit compatible.
5. Click in 32-bit or 64-bit, select Generate 64-bit, and then next
6. Keep clicking Next to go to the following page for Settings
-
In VM Parameters, enter -dfile. encoding= UTF-8
-
Add jar package page and click OK to finish
-
Select Main, the Main method of the package
Note: You need to select the Class loader for the Spring project Class Path
7. To continue to the next
- Set the JDK version for the program to run, in this case 1.8
- Click Search Sequence to set up the JRE packaging environment.
8. Click Search Sequence to set jre
- Select the “Directory”
- Be sure to type.\jre as I did
- Click ok
9. Click Next to select Client hotspot VM
10. Clicking Next will generate an.exe program on your desktop
Don’t get too excited about opening the program, don’t get too excited about it, you need to integrate the JRE environment into the program so that the package can run on a computer without the JDK.
11. Open the installed Inno Setup 5 and create File in the upper right corner
- Go ahead and click Next
-
Set the name and version of the application.
-
Click Next until the following page appears. Click on both buttons to add the.exe program generated on your desktop.
-
Click Next all the way to this page to set the language (no Chinese)
-
Click Next, set the file output path (the desktop selected here), and set the name of the compiled output. Exe generated by exe4j is on the desktop, so it is not recommended to set the path of the compilation output on the desktop, and the subsequent compilation will report a thread error, which will automatically delete the.exe generated by exe4j. You can create a separate folder here as the output directory.
-
Click Next and finish, and you will be prompted if you want to compile now. Select “No” and set the JRE path to compile again.
-
Add to the last line: #define MyJreName “jre”
-
Change the second line to the local JRE environment path
Source: “local JRE environment path \*”; DestDir: “{app}\{#MyJreName}”; Flags: ignoreversion recursesubdirs createallsubdirs
-
Then compile directly, it will prompt you to save the script, you can give it a name, the next compilation can continue to use.
-
When the green scroll bar ends, the compilation and packaging is complete
When the package is finished, you will be prompted whether to install it directly. Now you can install and run it directly. Don’t forget to check the shortcut.
Share the installer directly and you can install it on other computers.