Discuss the JAR File

Source: Internet
Author: User
Next we will discuss the JAR file-general Linux technology-Linux programming and kernel information. The following is a detailed description. A few days ago, I read a tutorial on using JAVA (second edition) from Tsinghua University, which contains some content about the JAR file, which is excerpted as follows for your reference:

1. compress the application into a jar file

You can use jar.exe to compress some files into a JAR file to release our applications. We can compress the classes involved in java applications into a JAR file, such as Tom. jar, and then use the java interpreter (using the parameter-jar) to execute the compressed file, or double-click the file to execute the compressed file.
Java-jar Tom. jar
Assume that there are two classes A and B in the application, where A is the main class. To generate A JAR file, follow these steps:
(1) first, use a text editor (such as notepad in Windows) to compile a configuration file Mymoon. mf:
Manifest-version: 10
Main-Class:
Created-By: 1.2.2 (sun Microsystems Inc .):
For example, save Mymoon. mf to D: \ test. It should be noted that, when writing A list file, between "Manifest-version:" and "1.0", between "Main-Class:" and the Main Class ", and "Created-By:" and "1.2.2" must have only one space.
(2) generate a JAR File
D: \ test \ jar cfm Tom. jar Mymoon. mf A. class B. class
The c-edge parameter must generate a new JAR file. f indicates the name of the JAR file to be generated. m indicates the name of the file list file.
Note: If the machine has installed the WinRAR decompression software and associated the. jar file with the decompression software, the Tom. jar file type is WinRAR, so that the Java program cannot run. Therefore, when releasing the software, we should also write another bat file Tom. bat with the following content:
Javaw-jar Tom. jar

2. Compress classes into jar files

We can use jar.exe to compress bytecode files of some classes into a JAR file, and then store the JAR file in the extension framework of the JAVA Runtime Environment, store the JAR file in the jre \ lib \ ext folder of the JDK installation directory. In this way, other programs can use the classes in the JAR file to create objects.
Now, we will compress Test1.class and Test2.class in D: \ test into a JAR file Jerry. jar:
Test1.java

Public class Test1
{Public void fTest1 ()
{System. out. println ("I am a method In Test1 class ");
}
}


Test2.java

Public class Test2
{Public void fTest2 ()
{System. out. println ("I am a method In Test2 class ");
}
}

(1) first write a configuration file (Manifestfiles)
Moon. mf
Manifest-version: 1.0
Class: Test1 Test2
Created-By: 1.2.2 (Sun Microsystems Inc .)
Save moon. mf to D: \ test
(2) generate a JAR File
D: \ test \ jar cfm Jerry. jar moon. mf Test1.class Test2.class
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.