From: http://www.cnblogs.com/icewee/articles/2073203.html
Preface:
We all know that Java can convert binaryProgramPackage it into an executable JAR file. Double-click the JAR file and double-click the EXE file to achieve the same effect, but it still feels different. In fact, this executable JAR file is also required to package Java programs into exe.
Preparation:
Eclipse and exe4j (software and account downloads are available online)
Step 1: Package the Java project into an executable JAR file. First, let's take a look at my java project structure, main. java is the program entry class, which contains the main function. The Config directory contains some configuration files, and Lib is the third-party class library used.
Start packaging, simulate (Java project)-Right-click-export
In the pop-up window, select "JAR file" and click "Next"
Deselect the "Config" and "lib" directories, and the project configuration files ". classpath" and ". Project" generated by eclipse, and click "Next"
By default, click "Next"
In the pop-up window, select the created manifest. MF file and click "finish"
The content of my manifest. MF file is:
Manifest-version:1.0
Main-class: Bing. Main
Class-path:. lib/ojdbc14.jar lib/poi-2.5.1. Jar lib/jbcl. Jar lib/jtattoo. Jar lib/liquidlnf. Jar
Created-by: icewee
You can specify "Main-class" to execute jar files. In fact, we finally package the project into an EXE, and the class-path can be left unspecified. We also need to specify the classpath when packaging the exe.
Step 2: Package the project into an EXE. It should be clear that not all files are packaged into an EXE, but resource files cannot be packaged.
First, create a folder in any directory. It is better to name it the same as the project name. I created a "simulate" folder on drive F, all the resource files and the executable jar files we generated (My simulate. jar) are copied to this folder, the config directory and the lib directory. If you are afraid that JRE is not installed on the machine that runs the program, then you need to copy the JRE directory on your machine, the jre5 I installed, and the final directory structure:
Open exe4j, skip welcome, and click the second item in the left-side navigation bar, because we have packaged the Java project into an executable JAR file in advance.
In the displayed window, select "jar in EXE mode" and click "Next"
In the new window, get a name for our application, select the EXE directory (my F: \ simulate), and click "Next"
Name the EXE we want to generate. If you want to generate a custom icon, select your ICO file. If you don't want to run multiple programs on one computer, you can check "allow only a single... ", click" Next"
Click "+" in green to set the class path for running the program.
Select our own executable JAR file (My Simulate. Jar) and click OK.
Our Simulate. jar is added to the class path.
Then, click the main class selection button in general. In the pop-up window, exe4j will automatically search and list all the jar files under the current class path that contain the main method class, because currently I only select the jar of my project, but only main. jar contains the main method, so you can easily select it and click "OK". The program entry class is set.
After the main class is set, add all required third-party class libraries to the class path in sequence. In the same way as adding "Simulate. Jar", click "Next"
Enter the minimum Java JRE version, that is, the JRE earlier than this version cannot run the program. Then click "advanced options"-"search sequence" to set our JRE. As mentioned earlier, what if JRE is not installed on the client ?, It's okay. We need to bind one.
Click "+" in green to select the JRE location of the bundle.
In the dialog box that appears, select directiony and select the JRE folder. Note: The JRE directory copies the JRE directory of the local machine to the directory generated by the current exe, my directory is F: \ simulate \ jre5, and the program uses a relative directory. Click OK to complete JRE bundling.
After JRE is bundled, click "Next"
By default, click "Next"
By default, click "Next"
By default, click "Next"
Generating exe
OK. Click "exit ".
Let's see how it works!
And the "Config" directory!