Under Windows, double-click the Java Software Packaging scheme that you can run

Source: Internet
Author: User

Source: http://www.cnblogs.com/shiyangxt/

Just beginning to learn Java, very depressed, write out of the Java class file, need dos under the compiler, and then DOS run to see the effect. This allows beginners to often

Feel the trouble and learn in depth later, will be exposed to eclipse, Netbean and some plug-in IDE products. Greatly facilitates the writing of Java, but with its own written program

More and more, gradually become a project and software, it is necessary to often deal with jar files. Gradually want to make Java file execution more fun, do not want to show others a small

The software is also in the IDE to see the effect, very not handsome. Now it's time to sort out a couple of Windows and double-click to run Java programs, just to make the. exe and. jar files.

----------------------------------------------------------------------------------------

The following part is taken from the Internet, I really do not bother to write directly down.

The first is to package the method of running the jar file.

Now windows will be loaded with J2SE parser, so that is to say, if packaged into a jar file, open with this J2SE parser can double-click Run.

Here is the packaging method for the jar package ************************

1. Build MANIFEST.MF (under the class file root)
The following content is the basic content of the file
==================
manifest-version:1.0
Main-class:a (Path of the main class)
CREATED-BY:ABC Company (creator name)
==================

2. Packaging
According to the conditions given by LZ
Execute under the class file directory
Jar CVFM Classes.jar MANIFEST. MF * *

The above command packages all files under class to Classes.jar, generated in the class directory

3. Implementation
You can do this by double-clicking on Windows.

-----------------------------------This is my recommended solution because it's simple.

MANIFEST. MF file Detailed **************************

Open Java jar File We can often see the file contains a Meta-inf directory, which will have some files, which

There must be a MANIFEST.MF, which describes a lot of information about the jar file, and the MANIFEST.MF file is described in detail below

, first look at the contents of the MANIFEST.MF file contained in Struts.jar:

manifest-version:1.0
Created-by:apache Ant 1.5.1
Extension-name:struts Framework
Specification-title:struts Framework
Specification-vendor:apache Software Foundation
specification-version:1.1
Implementation-title:struts Framework
Implementation-vendor:apache Software Foundation
Implementation-vendor-id:org.apache
implementation-version:1.1
Class-path:commons-beanutils.jar Commons-collections.jar Commons-digester.jar Commons-logging.jar

Commons-validator.jar Jakarta-oro.jar Struts-legacy.jar

If we classify the configuration information in manifest, we can summarize the following categories:

I. GENERAL properties

1. Manifest-version
Used to define the version of the Manifest file, for example: manifest-version:1.0

2. created-by
Declares the creator of the file, typically this property is generated by the JAR command-line tool, for example: Created-by:apache Ant 1.5.1

3. Signature-version
Defining a signature version of a jar file

4. Class-path
The application or class loader uses this value to build an internal class search path

Two. Application-related properties

1. Main-class
Defines the entry class for the jar file, which must be an executable class that, once defined, can run the jar file through Java-jar X.jar.

Three. applets (applet) related properties

1. Extendsion-list
This property specifies the list of extended information required by the applet, and each name in the list corresponds to the following attribute
2. <extension>-extension-name
3. <extension>-specification-version
4. <extension>-implementation-version
5. <extension>-implementation-vendor-id
5. <extension>-implementation-url

Four. Extended Identity Properties

1. Extension-name
This property defines the identity of the jar file, such as the Extension-name:struts Framework

Five. Package Extension Properties

1. Implementation-title defines the title of the extension implementation
2. Implementation-version defines the version of the extension implementation
3. Implementation-vendor defines the organization that extends the implementation
4. Implementation-vendor-id defines the identity of the organization to which the extension is implemented
5. Implementation-url: Define the Extension package (URL)
6. Specification-title defines the title of the extension specification
7. Specification-version defines the version of the extension specification
8. Specification-vendor declares the organization that maintains the specification.
9. Sealed defines if the jar file is sealed and the value can be true or false (I don't quite understand that)

Six. Signature-related properties

Signature Properties We can refer to a section of the Mail.jar provided by JavaMail

Name:javax/mail/address.class
Digest-algorithms:sha MD5
sha-digest:ajr7rqnn//cdygouxbd06msvfi4=
md5-digest:zntiq2aqatsniowxi1pqpw==

This section defines the class name of the class signature, the algorithm name of the calculation digest, and the corresponding digest content (encoded using the BASE64 method)

Seven. Custom attributes

In addition to some of the properties mentioned earlier, you can also add your own properties and the values of the responses in MANIFEST.MF, such as the J2ME program jar package may contain the following information

microedition-configuration:cldc-1.0
Midlet-name:j2me_mobber MIDlet Suite
midlet-info-url:http://www.javayou.com/
Midlet-icon:/icon.png
Midlet-vendor:midlet Suite Vendor
MIDlet-1: Mobber,/icon.png,mobber
midlet-version:1.0.0
microedition-profile:midp-1.0
Midlet-description:communicator

The point is, how do we read this information? In fact, the JDK provides us with an API for handling this information, and for detailed information, see

In the Java.util.jar package, we can get manifest information by passing the path of a jar file to Jarfile and then calling Jarfile's Getmanifest method.

Scenario **************************** for packaging. exe files

For Windows users, it's best to package a Java application as an. exe, and now I'll show you two methods.

1, with professional application packaging tools Installanywhere, this software can run on almost all platforms, of course, you have to download to the platform you need! And it also

Can be packaged as a setup program for each platform.

2, with the Mini free tool javalunch,javalauncher download URL is:

http://www.rolemaker.dk/nonRoleMaker/javalauncher/marner_java_launcher.htm

The downloaded file is a compressed package named Javalauncher.zip, after extracting the directory structure:


The source directory contains the Javalauncher program, which is written in C language.

L Changes.txt is a revised description of the new version

L Launch.exe is the main program

L LAUNCHER.CFG is a configuration file

L readme.txt are some instructions and examples

We only need to Launch.exe, launcher.cfg two files, copy the two files to the directory where the packaged files are located. Launcher.cfg is a text file with only three lines of content and modifies it as follows:

. \java1.4.2\jre\bin\javaw.exe

-jar Myswt.jar

The first line sets the directory that points to the jar package Myswt.jar, because Launch.exe and Myswt.jar are in a directory, so use "." That is the current directory.

L The second line sets the path to Jre\bin\javaw.exe.

Once you have configured Launcher.cfg, double-click Launch.exe to run the Java application.

If you look at how Eclipse starts, you find Eclipse and javalauncher the same principle: Eclipse.exe is equivalent to Launch.exe,startup.jar equivalent to Myswt.jar. But Eclipse.exe not like Launch.exe to have commonality, so it does not *.cfg such a configuration file, but the startup information is solidified in the Eclipse.exe.
Another: Landscaping icons
The icon for the Launch.exe file is too dull, so let's change it for a good show. To change the program's icon need to use a free software: Resource Hacker, it has the Chinese version, the download URL is:
http://www.users.on.net/johnson/resourcehacker/
Because this software has the Chinese version, here I will not say more, quite simple.------------------------wrote such a lump, I did not read it. Did not study the mood of the tool.

Plugin implementation. exe file export ****************************

A Jsmooth
1. Produced
Jsmooth,sourceforge.net
2. Type
Free
3. Download
http://jsmooth.sourceforge.net/download.php
4. Steps
A) Use eclipse to make the desired main class into a standalone jar package, noting the addition of the manifest attribute and the MainClass.
b) Create a new Jsmooth project
c) Select "Console" or "windowed" in the Sketlon
d) configuration in executable:
I. Executable Binary: Fill in the name of the destination output source. such as Test.exe.
Ii. executable icon: Choose a good watch
III. Current Driectory:. (indicates the present project directory, of course, it is possible to change to another, as you wish.)
e) configuration in application:
I. Classpath: Select the jar package that we generated and the class library that is required to run the jar file
II. MAIN-CLASS: Select the main class that we want to run.
Iii. optional use of an embedded jar: the class library that may be required to run the EXE (there can only be one class library).
f) configuration in JVM selection:
I. Minimum JVM version: Write a minimum of JVM-like versions required to run the program, such as 1.4
g) Compile:ok, after compiling successfully, there will be a new EXE program in your output directory. Just enjoy it.
Two exe4j
1. Produced
Ej-technologies
2. Type
Shared software,needs License
3. Download
http://www.ej-technologies.com/download/exe4j/files.php
4. Steps
A) Use eclipse to make the desired main class into a standalone jar package, noting the addition of the manifest attribute and the MainClass.
b) Create a new EXE4J project
c) Select "JAR in EXE" mode
d) configuration in Configure application:
I. Short name: Write casually.
II. ourput driectory: Select the output path.
e) configuration in Configure executable:
I. Executable type: There are three options, graphics, console. or service. Let's start with the simple point, here we choose Console
II. Executable name: Fill in the names of the destination output sources. such as Test.exe
Iii. icon File:exe file, but must be an. ico file
f) configuration in Configure Java invocation:
I. Classpath: Select the jar package that we generated and the class library that is required to run the jar file
II. MAIN-CLASS: Select the main class that we want to run.
Iii. Arguments (optional): input parameters. We don't need it here.
g) configuration in the Configure JRE:
I. Minimum version: Write a minimum version of the JVM required to run the program, such as 1.4
h) always next, the option for the steps encountered is default until Finish:ok. After compiling successfully, there will be a new EXE program in your output directory. Just enjoy it.
Three summary and comparison
There are many tools to generate EXE from Java, the above two are I personally feel that it is more convenient to use. The principle of the two are basically the same, but the specific use of a little bit different:
1. The same point
A) The most common point of course is that their principle is interoperable. is to execute the executable jar package by using a runnable Java program. Convert again.
b) The generated EXE executable program needs to run in a JVM environment with a higher than minimum version.
2. Different points
A) when generating EXE, if you want EXE to only need the pure JVM environment (do not need a third-party class library) can run. The jsmooth need to compress all of the third-party libraries into a jar package (because it has a embeded jar option), which is cumbersome, because when more jars are needed, they need to be decompressed first with JAR–XVF, using jar– CVF re-create the new jar file and put it in the embeded jar option, and exe4j will compile the jar package used in Classppath into the EXE.
b) Jsmooth is free, and exe4j is shareware, need to register, or in the execution of EXE will pop up annoying prompt box.
c) ico file selection: exe4j requires a strict ICO file, while Jsmooth can be compatible with a variety of other images such as JPG.

Windows double-click to run Java Software Packaging Scheme (GO)

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.