How Java programs generate jar, EXE, and installation files

Source: Internet
Author: User
Tags export class

http://blog.csdn.net/luoweifu/article/details/7628006/

first, with Eclipse Production Jar file

First, look at the directory structure of my project:

1, Project name above right click, select Export, in select Java\jar file, next;

(2), select, src folder,. Classpath and. Project can be removed without selecting. Select the export distination (choose Output Path), next.

(3), remove the option to export class files Withcompile errors (also output class file when compiling error), click Next.

(4), select the class containing the main method in main class and click Finish.

(5) The warning jar Export finished with warings may appear, see details for additional information. Select OK.

(6), errors that may occur

If the above process can be successfully completed, congratulations, this process is complete, generate a JAR file success! However, sometimes an error occurs after (4), such as:

At this point, the class is resolved by:

1) Check the file under the Bin folder under the project is complete, the process of making a jar package is essentially compressing the files (class files, pictures, jar packages, etc.) under the Bin folder into the jar package. Open the directory structure of the project you will find: in the SRC folder, some files under the Bin folder are the same copy (the. java file corresponds to a. class file).
2), refresh the project , select the items you want to package, right click on the mouse, select Refresh. The effect is that content that may have changed is not copied to the Bin folder in a timely manner.
3), in the project directory, and SRC peers to build a Meta-inf folder,
Build a METAINF.MF inside,
It specifies the code for the Main-class and program run,

The code I wrote is:

manifest-version:1.0

Main-class:execute. Structure

Class-path:. Lib/jfreechart-1.0.1.jar lib/liquidlnf.jar Lib/nimrodlf-1.0b.jar Lib/substance.jar

The path of the imported package

Created-by:loweifu

In the 4th step, select Use exiting manifest from workspace, such as:

second, using exe4j executable. exe file

The software that can generate the. exe file has a lot to check, I only use exe4j here, first download a exe4j and install. Assuming your project has been successfully packaged as a jar file, you can do the following.

First, create a folder in any directory, preferably named and the project name is the same, I created a "datastructure" folder on e disk, and then all the resource files and the executable jar file we generated (my Datastructure.jar) are copied to this folder, Lib directory, if you want to make the other computer can use the program without installing JDK, you need to copy the JRE directory on your machine, I installed the Jre6, the final directory structure is as follows:

1. If you have saved the project package configuration file, then click >>open to open the next.

2. Project type-Select Packaging method

Select "Jar in EXE"

3. Application info-configuration of the generated application information

Select the name of your application and the output folder of the executable file that will be generated. Then >>next.

4. Executable Info-Configure the parameters of the executable file

If only the generated EXE file is allowed to open at the same time only one program is running, then put the "allow only a running instance of the application" option on the hook. The "icon File" entry represents the icon after the EXE file is generated, and a picture is selected in an ". ico" format. Click Next

5. Java invocation-Configuration Operating environment

In the Class Path box, clear the original class path path, click on the right side of the "+" to select the packaged jar file

(1), select the jar file to import in archive, such as:

Click "OK" and the results are as follows:

(2), select the entry class in main class, that is, the class containing the main function.

Then click Next

After the Main class setting is complete, add all the required third-party classes (that is, the external classes) to class path, and then click "Next" as the "Datastructure.jar" method.

6, jre-configuration JRE "The following (1), (2) point is very important"

Enter the version number of the minimum and maximum JDK allowed in minimum and maximum respectively.

If you want to bundle the JRE in this program, enter the Configure search sequence option:

(1), the search Windows registry reserved, if not, click the green "+", select "Search Registry", and then click "OK" such as;

(2) Delete all other directory, especially if there is "Java_home" or "jdk_home" must be deleted, because he will save your java_home address, installation will appear the path can not be found errors;

(3), click the green "+" to select the bundled JRE location

Select the JRE you just copied, such as:

Select one of the preferred VMS-Select the virtual machine type, I choose the Default vm.

7, next there is no particularly important configuration , according to the need to choose some parameters, you can directly next,next, know the completion.

8. Problems that may arise

The prompt box may appear every time you open an EXE file: This executable is created with an evaluation version of EXE4J

This is because you have not registered EXE4J software, after registration will not be prompted. Online search of a registration code: L-G782DN2D-1F1YQXX1RV1SQD.

Third, make the program you write to be able to install under Windows software

First, you go to the next Inno Setup, the installation is very simple, needless to say, directly according to the prompt installation. Download Link: Http://www.crsky.com/soft/7195.html#down

Inno Setup is a free Windows Installer maker, and I'm using Inno setup v5.4.3.

Method One: 1. Edit the Script program

My script is as follows:

[Setup]
Appname= Data Structure Demo program
appversion=1.5
Defaultdirname={pf}\datastucture
Defaultgroupname=datastucture
; Uninstalldisplayicon={app}\myprog.exe
Outputdir=d:\java

[Files]
Source: "e:\datastructure\jre\*"; DestDir: "{APP}\JRE"
Source: "e:\datastructure\jre\bin\*"; DestDir: "{app}\jre\bin"
Source: "e:\datastructure\jre\bin\client\*"; DestDir: "{app}\jre\bin\client"

Source: "e:\datastructure\jre\lib\*"; DestDir: "{app}\jre\lib"
Source: "e:\datastructure\jre\lib\audio\*"; DestDir: "{app}\jre\lib\audio"
Source: "e:\datastructure\jre\lib\cmm\*"; DestDir: "{APP}\JRE\LIB\CMM"
Source: "e:\datastructure\jre\lib\deploy\*"; DestDir: "{app}\jre\lib\deploy"
Source: "e:\datastructure\jre\lib\ext\*"; DestDir: "{app}\jre\lib\ext"
Source: "e:\datastructure\jre\lib\fonts\*"; DestDir: "{app}\jre\lib\fonts"
Source: "e:\datastructure\jre\lib\i386\*"; DestDir: "{app}\jre\lib\i386"
Source: "e:\datastructure\jre\lib\im\*"; DestDir: "{App}\jre\lib\im"
Source: "e:\datastructure\jre\lib\images\cursors\*"; DestDir: "{app}\jre\lib\images\cursors"
Source: "e:\datastructure\jre\lib\management\*"; DestDir: "{app}\jre\lib\management"
Source: "e:\datastructure\jre\lib\security\*"; DestDir: "{app}\jre\lib\security"


Source: "e:\datastructure\jre\lib\zi\*"; DestDir: "{App}\jre\lib\zi"
Source: "e:\datastructure\jre\lib\zi\africa\*"; DestDir: "{App}\jre\lib\zi\africa"

Source: "e:\datastructure\lib\*"; DestDir: "{app}\lib"
Source: "E:\DataStructure\DataStructure.exe"; DestDir: "{app}";

[Icons]
Name: "{group}\datastructure"; Filename: "{app}\datastructure.exe"

Here's a little explanation:

[Setup This section contains the global settings for installing programs and uninstalling programs.]

AppName (to install) the program name

AppVersion Program Version number

Defaultdirname the default folder when installing

Defaultgroupname default folder for shortcut menu or Start menu

OutputDir the output path of the Setup program

[Files] This is an optional file segment that defines the setup installation file to the user's system.

Source Resource File

The Destdir file is installed to a directory in the user's system.

[Icons] This optional excerpt defines all shortcuts created in the Start menu and/or other locations (such as the desktop).

Name and location of the shortcut to create.

The command-line file name of the filename, usually beginning with a directory constant.

2. Compiling

After editing the script, select "Build" \ "Compile" to finish.

Method Two:

Select File/New to open the Inno Setup Script Wizard to create a new script file.

According to the prompt step-by-step, this is a single room, I will not say more.

In this case, I wrote the program and completely packaged, like a complete software. "Oh, you are a software engineer!" :-D:-D "haha ... A joke!

How Java programs generate jar, EXE, and installation files

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.