Java package EXE installation package with JRE self-start

Source: Internet
Author: User

It was another boring weekend. I tried my best to come up with a Java program package solution.

Purpose: To install an installation package, just like installing QQ, you can continue the next step. You can uninstall the package and require the program to start automatically. You do not need to install JRE separately. When writing this solution, I hate Microsoft. ah, helpless. fortunately, I finally came up with it. Let's share it. I 've never written a blog for a long time.

Step 1: Delete JRE/lib/RT. classes not used in jar, delete charsets. character Set encoding not used in jar. mywork open source project (http://mywork.sourceforge.net/) with a slimming jre6.0, very small only a few M. if necessary, you can properly add fertilizer on this basis. For example, if a class cannot be found, you only need to Rt in the complete JRE. in the jar package, find the package of this class and add it to the reduced JRE.
Step 2: Use pack200 for compression. The compression effect is amazing. For details, refer to the official manual. The following is the simplest compression and decompression command (if you want to create an installation package, do not compress it, because it is not convenient to decompress, you need to write another program to decompress the package)
Compression command D:/XXXXX/pack200 rt.jar.pack.gz Rt. Jar
Unpack200-r JRE/lib/RT. Jar. Pack JRE/lib/RT. Jar
Step 3: compress your program into a jar package. Pay attention to specifying the main class and put it under JRE/lib/EXT together with the dependent jar package. (Of course, you can also skip this step, specify classpath through write batch processing) The benefits of putting it directly under ext will be shown below

Step 4: Write the startup batch processing % 1 in the upper directory of the JRE folder.
@ Set Path =./JRE/bin; % 1; % PATH %;
@ Start javaw com. Main (change it to your program portal as needed)

Rename the local JRE or JDK folder, and press Java under cmd to confirm that the local JRE has expired. Click batch processing to test if the program starts normally, if the program cannot be started, @ start javaw COM. main is rewritten to Java COM. main restarts debugging to see if there are missing classes.

Step 5: Compile the batch processing into an EXE program, use the quick batch file compiler tool (http://www.abyssmedia.com/download.shtml), the program is very simple to use here is not introduced, if the E file is poor, you can download Chinese in the new century in Chinese. Note that if you want to create an installation package, you must use the ghost mode, rather than the Console mode.

Step 6: Create the installation package using the innosetup tool (Baidu has been downloaded everywhere). This tool has a wizard, which will not be described. After the Wizard is complete, a prompt will be prompted to generate the script, save the script, generate the EXE installation package, and run the installation package. If the structure of the generated file program is the same as that in Step 4, and the installation package can be run, the installation package is created. (this step selects the program file when the batch processing EXE and JRE are added together. Note that the JRE must not be compressed by pack2000; otherwise, you need to write another decompression program in the installation script)

Step 7 automatically starts the program with windows. Modify the installation script and add the following code:
[Registry]
Root: HKLM; subkey: "software/Microsoft/Windows/CurrentVersion/Run"; valuetype: string; valuename: "program name"; valuedata: "{app}/main program .exe" {app}/JRE/bin """

% 1 is used in this case when the system is started. it does not represent the folder where the program is located, so the JRE folder parameter is passed here, @ set Path =. /JRE/bin; % 1; % PATH %; add JRE to path.

Step 8 log out and log on again to see if the program is automatically started. (You can test it on a machine without JRE installed)

 

The size of my installation package is about 10 MB. I rely on many third-party jar packages. Otherwise, it can be smaller. I can add a shell or use RAR to compress the package.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.