Use the command line to package the Java program as a jar File

Source: Internet
Author: User

How can I package a written Java program into a jar file? You can select either of the following methods:

1. Command Line Method:

Package
Jar cf JAR File Name: program file name or folder of the program
Example:
Jar cf MyApp. jar D: JavaProjectMyApp

View the content of a jar file
Jar tvf JAR file name
Example:
Jar tvf MyApp. jar

Decompress a jar File
Jar xf JAR file name
Example:
Jar xf MyApp. jar

Add files to the compressed package

The file added by the jar xf JAR file name or other jar files
Example:
Jar xf MyApp. jar Test. class

Update a jar File
Jar uf JAR file name Update file or other jar files
Example:
Jar uf MyApp. jar Test. class

Run a jar Program
Java-jar JAR File Name
Example:
Java-jar MyApp. jar

Create a jar file that can be run
First, we must have a Main Class)
Create a text named MANIFEST. MF and copy the content to it.
Manifest-Version: 1.0
Main-Class: YourMainClass
YourMainClass is the class that your program contains the main method.
The following statement is used to create an executable jar file.
Jar cvfm MyApp. jar MANIFEST. MF file or folder path

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.