Using EXE4J to execute a Java project as an EXE execution program

Source: Internet
Author: User

Recently wrote a small tool in Java, want to put it into EXE executable file, then directly put in a directory, the execution can run.

Tools to use:

1, write the project: can be a Java project, can also be a Java Web project

2. Tools to play jar: I use the myeclipse development, they have their own tools, I use this directly

3, exe4j: can go online download, address: http://www.ej-technologies.com/download/exe4j/files.html, there are green version and installed, 32-bit and 64-bit. I am someone else to the installation version, with the latest version of the official website may have some discrepancy, there is a need to download the attachment.

4, Jre:java the operation of the project can not be separated from the JRE, also cannot ask the customer to install the JDK, so still give it a more insurance. (After the JDK installation, there are JDK and JRE two directories, you can copy the JRE folder directly, or you can copy the JRE under the JDK folder.) The JDK I use here is 1.6).

5, a suffix named ico icon file, as an EXE executable program icon. can also not.

Let's get started.

To compress the SRC in the project into a jar package:

1. My directory structure:

2. Right-click on the project name (or right-click in the left margin), select "Export", which is the exported file, find "Java---JAR file" in the popup box, and then "Next".

3. Remove the check status of other files except SRC, select the src folder only. Then select the location where the current jar is to be saved. The last three options the default is the first one is checked, and the latter two are unchecked. Let's hook it up here, nothing more than to create a new folder if the selected folder does not exist, and overwrite it if it already exists. If you do not check the specified directory under the detection of the specified file will pop-up box asks you whether to overwrite. After you finish the above three, click "Next".

4. Use the default settings and click "Next".

5, the next step, all the way to the default. During the period, you may encounter a problem, such as. This is a two-warnings. No need to take care of it. If you feel uncomfortable and do not want to have, check the information on the Internet, said that the fourth of the two hooks are removed will not have this warning. (I tried, and there was no warning, but after generating an EXE execution program, it was reported that the two files that were warned were missing.) Look at those two checked content, one is to say the wrong one is to say that the warning, with my this can not find the file half a dime relationship is not, so it may happen to meet the wrong. )

6. At this point, the selected directory should have the exported jar package.

Second, the organization directory structure:

Copy the other folders inside the Java project (I'm Lib and log two folders) to the same directory as the jar you just exported, and put the exported jar package into the Lib directory. Create a new image or other name folder for the EXE generated icon (also can be placed directly under the root directory, I was placed under the Image tab), and finally copy the JRE folder here. My directory is as follows:



Third, use the EXE4J tool to generate EXE execution program:

1, after the installation completed EXE4J tool, double-click will open the Welcome interface, this interface is used to lose the registration code, if you do not lose, you can directly next. But if you do not input, double-click the generated EXE, will alert out a paragraph,. You must click OK to execute the program.

In order not to let the problem become a "customer feedback problem", we still enter the registration code bar. Click the "Enter License" button to enter name, company, and license Key. The first two can be randomly lost, key can try the following.

License Key:

A-xvk258563f-1p4lv7mg7sav
A-xvk209982f-1y0i3h4ywx2h1
A-xvk267351f-dpurrhnyarva
A-xvk204432f-1kkoilo1jy2h3r
A-xvk246130f-1l7msieqiwqnq
A-xvk249554f-pllh351kcke50
a-xvk238729f-25yn13iea25i
A-xvk222711f-134h5ta8yxbm0

2, lisence input completed click "OK" back to the Welcom interface, click "Next" in "Choose Project type" inside the "jar in EXE mode", that is, with the jar package to generate EXE. Next.

3, the directory configuration, that is, which folder below the thing to play EXE. In general, fill in the abbreviated name of the application, direcotries inside Select the directory to generate EXE, that is, the directory structure of the above organization. Last next.

4, exe execution program configuration.

Executable Name: exe executable

Icon File:exe executes the icons for the file. Here, select the ICO file under Image. Only ICO files can be used as icons here. You can also cancel the previous check box does not give the current EXE settings icon, if not set the system will automatically set an icon according to the system theme.

Allow only a single ... : Only one EXE program is allowed to run on a computer, if multiple is allowed, you can uncheck

Finally click on "Next".

5, invocation configuration. That is, adding a jar file and specifying the Main method. Click the green "+" sign, and in the pop-up box, select the Jar package (2) in Lib and then "OK". This can only be added one by one, if the use of the jar package is more cumbersome.


After the jar in Lib has been added, specify the main method, click the button after "main class", find the Main method of the program in the popup box, and add it in.


After both steps are OK, the final result is:

Sometimes the system in addition to the use of the jar package, but also to use the DLL file, and the above steps to add a jar can not add DLL files, the DLL file in the same directory as the EXE, because the DLL problems caused by the system error, even put in the System32 folder is useless. I am in this system, there are DLL files, tossing the majority of days, but also find a long time of the information (find the process found a lot of people in this step is also very distressed), and later found that, in fact, exe4j long considered this problem, is in the advanced Options, namely:

Can through this add any non-DLL files in the folder, the operation is very simple, click the Pop-up dialog box, click the green "+" sign, select the DLL file directory, I am here in the Lib directory, so choose Lib, after adding, the result is as follows:

6. Configure the JRE. Configure the minimum version of the JRE, which is below this version of the JRE that cannot run the program. The largest version is the same. The JDK I used is 1.6, so the minimum configuration is 1.6. The largest can not be set.

Then click on "Advanced Options"-"Search sequence", set up our JRE, because the customer's machine may not have a JRE, so we take a better ourselves. Click the green "+" sign in the pop-up box and select Direcotry in the Define search sequence entry, given the directory where the JRE resides. Then "OK".

After the JRE is added, the effect is as follows:

7, after the three steps are the default operation, all the way next. Until the following interface:

This interface shows that the build is complete. There are three points to be said:

1. Click here to start the application: This button is used to test the execution of the program, click on the button to launch EXE execution program.

2, Save as: This is very important. This saves the above steps of the process, save will generate a exe4j, later if you need to re-play the program EXE, run the exe4j file directly, the various configurations are stored in this file, basically all the way next, especially useful.

3, Restart: This Restart is a bit misleading. Restart is meant to be restarted, and in this case it is easier to understand the regeneration. I started to make a mistake, want to regenerate, so I ordered this, the results directly to me to jump to the first step back. Fortunately, the various settings are still there, if you give me empty I will not start again.

8. The final result should look like this:

Description: There is an icon set in the EXE above, in order to test I do not set the icon will appear what effect, I do not add an icon here. The others are the same.

Iv. what is organized to customers:

Create a new folder and copy the JRE folder and the generated EXE execution program to the folder. If the system inside the DLL file, which in one step also need to add DLL file information, the above mentioned in the add DLL file: is the choice of the DLL folder, here is the same, the DLL is located in the folder with the EXE peer, and then delete the inside of the jar package. Why did you do it? Because exe4j for these non-jar files will not be packaged like a jar in the EXE, it only records their specific location (that is, let us choose the DLL directory), so we need to manually add the DLL files and directories and directory name must be the same as the selected directory. Finally, double-click the EXE to test if the program is performing incorrectly.

This completes the process.

Source: http://1017401036.iteye.com/blog/2248488

Using EXE4J to execute a Java project as an EXE execution program

Related Article

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.