Implementation method of converting jar file into exe installation file
1. You should know whether the target file is 32-bit or 64 bit. If 32-bit is generated, you should use 32-bit JRE. If 64 bit is generated, you should use 64 bit JRE.
Figure 1
Select 32bit or 64bit at the circle position. Because I want to create 32bit, I use the default.
2. JRE configuration (report various java_home errors if it is not configured):
I first create a folder called "HJ assistant", and then put my executable program limitvic1 1. Jar and JRE folders are put in and generated later Exe files are also placed in this directory.
Figure 2
Click the sixth JRE search sequence in Figure 1, and the interface as shown in the figure will appear:
Figure III
Delete all three items, then re select the JRE directory, and specify the directory as the JRE folder in the "HJ assistant 1.1" folder. As shown in the figure:
Figure IV
That's how it came out The EXE executable file can be executed without reporting the error shown in the figure below. Send the folder "HJ assistant 1.1" to the computer, and the partners who do not have JRE installed can also use it.
3. Transformed Exe file cannot display picture resources.
My project is swing project, which needs some icons. Because it is Exe executes the file, so the class loader is needed when reading image resources, rather than the URL address directly.
Another important point is that the folder where pictures are placed must be a system resource folder, otherwise pictures cannot be obtained. Set the folder as a resource folder as shown in the figure.
4. Now that the runnable has been generated Exe file, but when it is used by others, it is necessary to put the JRE folder together. In this way, the size of the subfolder seems to reach more than 100 megabytes, but your original file is actually very small, so I use the inno setup packaging tool to package the folder into an installation file, which greatly reduces the occupied capacity. The use of inno setup tool is also very simple, and the Chinese version can be downloaded on the network. Here is a problem to pay attention to in the packaging process:
As shown in the figure: when adding a folder, add the upper directory of the JRE folder. In this project, it is the folder "HJ assistant 1.1", otherwise the JRE file cannot be found during operation.
According to the script wizard steps, you can produce it soon Exe installation file, with a size of more than 30 megabytes, is much smaller than the original folder.
The above is the implementation method of converting jar file into exe installation file brought by Xiaobian. I hope you can support more programming tips~