Jar command package with Java execution jar package

Source: Internet
Author: User
Tags unpack

Detailed jar command

jar {ctxu}[vfm0m] [jar-file] [manifest-file] [-C directory] File name ...

where {CTXU} is a subcommand of the jar command, each time the jar command can contain only one of the CTXU, each of which represents:

    • -C Create a new JAR file package

    • -t lists the contents list of the JAR file package

    • -X expands the specified file or all files of the JAR package

    • -U update the existing jar package (add file to jar file package)

Options in [vfm0m] can be either optional or optional, they are option parameters for the jar command

    • -V Generate detailed reports and print to standard output

    • -f Specifies the JAR file name, usually this parameter is required

    • -m Specifies the MANIFEST manifest file that needs to be included

    • -0 storage, no compression, so that the resulting JAR package will be larger than the size without the parameter, but faster

    • -M does not produce a manifest for all items (the Manifest) file, this parameter ignores the-m parameter

Create a jar package and display the packaging process
JAR-CVF Filename.jar Files

Create an executable jar package and display the packaging process
JAR-CVFM Filename.jar MANIFEST. MF files
View files in a jar package
JAR-TF Filename.jar
Unpack the jar package and display the packaging process
JAR-XVF Filename.jar
Add files to the jar package
Jar-uf Filename.jar Files
The-c parameter, which indicates the first switch to the test directory under the Execute JAR-CVF command
JAR-CVF FILENAME. Jar-c test/

Java Execution jar Package



Executing a jar package without a manifest file
Java-classpath Filename.jar MainClass


For example, there is a class called HelloWorld inside the Main method code is as follows:

public class Helloworld{public static void Main (String[]args) {System.out.println ("Hello World");}}

He then compiles it into a jar package, does not specify the class to add the MANIFEST.MF file or does not have the main method in place, and uses Java-jar Helloworld.jar will report no main manifest attribute, in Helloworld.jar error, you can use the Java-classpath helloworld.jar HelloWorld command to specify the main class execution

Execute JAR package containing jar package in jar package
Java-classpath Inner.jar-jar Filename.jar


The first to unpack a third-party jar package and package it with the project sometimes we need to refer to a third-party jar package, and when we pack it we need to hit the jar package with a third-party jar, and there are two ways:

    • The second use of the above command to execute, for example, there is a third-party jar package called Inner.jar with the project packaged into a jar file called Helloworld.jar use the Java-jar command to perform the report can not find the class exception, you need to use the upper command Java- Classpath Inner.jar-jar Helloworld.jar



Jar command package with Java execution jar package

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.