1. You need to be clear whether the target file is 32-bit or 64-bit. If the generated 32-bit, you need to use 32-bit jre. If the generated 64-bit jre, you need to use 64-bit jre.
Figure 1
Make a 32-bit or 64-bit selection in the circle position. Because I want to create 32bit, I use the default one.
2. JRE configuration (if not configured properly, various JAVA_HOME errors will be reported):
I first create a folder called "HJ Assistant", and then put my executable program limitvic1.1.jar and jre folders, and the generated .exe files are also placed in this directory.
Figure 2
Click the search Sequence of the sixth item in Figure 1, and the interface as shown in the figure will appear:
Figure 3
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 picture:
Figure 4
In this way, the exported .exe executable file can be executed and the error shown in the figure below will not be reported. Send the "HJ Assistant 1.1" folder to friends who do not have jre installed on the computer.
3. The converted .exe file cannot display image resources.
My project is a Swing project, which requires some icons. Because it is a .exe execution file, you need to use a class loader when reading image resources, and you cannot use the URL address directly.
ImageIcon icon = new ImageIcon(ImageIO.read(getClass().getClassLoader().getResource("frame.png")));Another very important point is that the folder where the picture is placed must be the system resource folder, otherwise the picture cannot be obtained. Set the folder as the resource folder as shown in the figure.
4. Since the runnable .exe file has been generated, but when it is used by others, you have to put the jre folder in it. This way, the size of the sub-folder seems to be more than 100 megabytes, but your original file is actually very small, so I used the Inno Setup packaging tool to package the folder into an installation file, which will reduce the capacity a lot. The method of using the Inno Setup tool is also very simple, and the Chinese version can be downloaded on the Internet. Here is a question that should be paid attention to during the packaging process:
As shown in the figure: When adding a folder, add the previous directory of the jre folder. In this project, it is the folder "HJ Assistant 1.1", otherwise the jre file will not be found when running.
According to the script wizard steps, you can quickly produce the .exe installation file, with a size of more than 30 megabytes, which is much smaller than the original folder.
The above is all the implementation methods for converting Jar files into exe installation files brought to you. I hope everyone can support Wulin.com~