Java projects packaged as EXE files

Source: Internet
Author: User

Objective:

We all know that Java can package binaries into executable jar files, double-click the jar and double-click the EXE effect is the same, but the feeling is still different. In fact, the Java program is packaged as EXE also requires this executable jar file.

Get ready:

Eclipse, exe4j (online with software and account download)

The first step is to package the Java project into an executable jar file, first look at my Java project structure, Main.java is the program entry class, there is the Main function, the Config directory is some configuration files, Lib is used by the third-party class library

650) this.width=650; "src=" Http://pic002.cnblogs.com/images/2011/60721/2011060515304551.png "style=" Border:none; " />

Start packing, simulate (Java project)-right mouse button-export

650) this.width=650; "src=" Http://pic002.cnblogs.com/images/2011/60721/2011060515334852.png "style=" Border:none; " />

Pop-up window, select "JAR file" and click "Next"

650) this.width=650; "src=" Http://pic002.cnblogs.com/images/2011/60721/2011060515344917.png "style=" Border:none; " />

Uncheck the "config" and "Lib" directories, and the Project Profile ". Classpath" and ". Project" generated by Eclipse, click "Next"

650) this.width=650; "src=" Http://pic002.cnblogs.com/images/2011/60721/2011060515384312.png "style=" Border:none; " />

All by default, click "Next"

650) this.width=650; "src=" Http://pic002.cnblogs.com/images/2011/60721/2011060515410010.png "style=" Border:none; " />

In the pop-up window, select the MANIFEST.MF file that we created and click "Finish"

650) this.width=650; "src=" Http://pic002.cnblogs.com/images/2011/60721/2011060515432930.png "style=" Border:none; " />

The contents of my MANIFEST.MF file are:

Manifest-version:1.0main-class:bing. Mainclass-path:. Lib/ojdbc14.jar Lib/poi-2.5.1.jar Lib/jbcl.jar Lib/jtattoo.jar Lib/liquidlnf.jarcreated-by:icewee

The purpose of the executable jar file is achieved by specifying "Main-class". In fact, we finally package the project into Exe,class-path can not be specified, in the packaging EXE when also specify CLASSPATH.

The second step, package the project into EXE, here to make it clear that not all the files are packaged into an EXE, the resource files can not be wrapped in, look down ↓

First, create a folder in any directory, preferably named and the project name is the same, I created a "simulate" folder on the F drive, and then all the resource files and our generated executable jar files (my Simulate.jar) are copied into this folder, Config directory and Lib directory, if you are afraid to execute the program on the machine does not install JRE, then you need to copy the JRE directory on your own machine, I installed the JRE5, the last directory structure:

650) this.width=650; "src=" Http://pic002.cnblogs.com/images/2011/60721/2011060515591027.png "style=" Border:none; " />

Open exe4j, skip the Welcome, and click the second item in the left navigation directly, as we have already packaged the Java project as an executable jar file in advance.

650) this.width=650; "src=" Http://pic002.cnblogs.com/images/2011/60721/2011060515520386.png "style=" Border:none; " />

In the pop-up window, select "JAR in EXE mode" and click "Next"

650) this.width=650; "src=" Http://pic002.cnblogs.com/images/2011/60721/2011060515521294.png "style=" Border:none; " />

In the new window, take a name for our app, then select the EXE build directory (my F:\Simulate) and click "Next"

650) this.width=650; "src=" Http://pic002.cnblogs.com/images/2011/60721/2011060516025629.png "style=" Border:none; " />

For the exe we want to generate name, if you want to create a custom icon, then select your ico file, if you do not want to run more than one of your programs on a computer, you can check "Allow only a single ...", click "Next"

650) this.width=650; "src=" Http://pic002.cnblogs.com/images/2011/60721/2011060516075183.png "style=" Border:none; " />

Click the green "+" to set the program to run the class Path

650) this.width=650; "src=" Http://pic002.cnblogs.com/images/2011/60721/2011060516122663.png "style=" Border:none; " />

First select our own executable jar file (my Simulate.jar) and click OK

650) this.width=650; "src=" Http://pic002.cnblogs.com/images/2011/60721/2011060516134493.png "style=" Border:none; " />

Our Simulate.jar is added to class path.

650) this.width=650; "src=" Http://pic002.cnblogs.com/images/2011/60721/2011060516195659.png "style=" Border:none; " />

Then click on the main class selection button in general, and in the pop-up window, exe4j will automatically search for the class that contains the main method in all the jars under the current class path, and list it because I currently only select the jar for my project. And my project only Main.jar contains the main method, so at a glance, directly select it click "OK", the program entry class is set to complete

650) this.width=650; "src=" Http://pic002.cnblogs.com/images/2011/60721/2011060516233423.png "style=" Border:none; " />

After the Main class setting is complete, add all the required third-party class libraries to class path, and then click "Next" as the "Simulate.jar".

650) this.width=650; "src=" Http://pic002.cnblogs.com/images/2011/60721/2011060516261526.png "style=" Border:none; " />

Enter the Java minimum JRE version number, which is lower than this version of the JRE cannot run the program, then click on "Advanced Options"-"Search sequence", set up our JRE, said before, if the client does not install the JRE do? That's okay we bundle one in

650) this.width=650; "src=" Http://pic002.cnblogs.com/images/2011/60721/2011060516300284.png "style=" Border:none; " />

Click on the Green "+" to select the bundled JRE location

650) this.width=650; "src=" Http://pic002.cnblogs.com/images/2011/60721/2011060516330494.png "style=" Border:none; " />

Select "Directiony" in the pop-up dialog, then select the JRE folder, note: This JRE directory is we copy the JRE directory to the current EXE generated directory, my directory is F:\SIMULATE\JRE5, the program uses the relative directory, click OK, Completing the bundle operation of the JRE

650) this.width=650; "src=" Http://pic002.cnblogs.com/images/2011/60721/2011060516352910.png "style=" Border:none; " />

After the JRE is bundled, click "Next"

650) this.width=650; "src=" Http://pic002.cnblogs.com/images/2011/60721/2011060516363574.png "style=" Border:none; " />

By default, click "Next"

650) this.width=650; "src=" Http://pic002.cnblogs.com/images/2011/60721/2011060516371365.png "style=" Border:none; " />

By default, click "Next"

650) this.width=650; "src=" Http://pic002.cnblogs.com/images/2011/60721/2011060516374440.png "style=" Border:none; " />

By default, click "Next"

650) this.width=650; "src=" Http://pic002.cnblogs.com/images/2011/60721/2011060516381611.png "style=" Border:none; " />

EXE in Build

650) this.width=650; "src=" Http://pic002.cnblogs.com/images/2011/60721/2011060516391366.png "style=" Border:none; " />

OK, finish, click "Exit" to

650) this.width=650; "src=" Http://pic002.cnblogs.com/images/2011/60721/2011060516400048.png "style=" Border:none; " />

Let's see what we've achieved!

650) this.width=650; "src=" Http://pic002.cnblogs.com/images/2011/60721/2011060516424155.png "style=" Border:none; " />

Our executable jar and third-party jar in total less than 5M, can jre5 directory of more than 50 m, if the target machine has a JRE environment can delete it, the Lib directory is a third-party jar file, is now packaged in the EXE, so it does not exist for reasons, then the minimum configuration is left " Simulate.exe "and" config "Directory!


Java projects packaged as EXE files

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.