Jar command to hit jar package

Source: Internet
Author: User

1. Preparatory work:

For the sake of convenience, here is an example of Project Class2json in Eclipse, the project structure is as follows:

Bin: is based on the execution. Java-generated. class file, the directory under the bin is the same as the SRC directory, except for the. class file Lib: External dependency package src: We wrote it ourselves. java files

Next:

1 . We create a new Class2json_jar folder 2 . Copy the files under the bin to Class2json_jar 3 . And the whole LIB to copy the past, the Lib renamed to Class2json3_lib 4. Create the Meta-inf folder and create the MANIFEST.MF file under the folder

In the MANIFEST.MF file, add the following: (write attention to the specification, the middle will be separated by a space, even if the next line, the beginning of a space)

(The first is the version number; the second is the extra jar package, and the third is the main class that starts)

1.0 Class-path:. class2json3_lib/commons-beanutils-1.8. 0 . Jar class2json3_ Lib/commons-collections-3.2. 1. Jar class2json3_lib/commons-lang-2.4. Ja r class2json3_lib/commons-logging-1.1 . 3. jar class2json3_lib/ezmorph-1  . 0.6. Jar class2json3_lib/json-lib-2.3-jdk15.jarmain-class: Com.zc.class2json.trans.test.TestDataClass2Json

2. Jar command to hit jar package

1) Jar Command usage

[Email protected]:~/zc/jar-package-example/class2json_jar$ Jarusage:jar {CTXUI}[VFMN0PME] [jar-file] [manifest-file] [Entry-point] [-C dir] files ... Options:-C CreateNewArchive-t List Table of contents forArchive-X extract named (or all) files fromArchive-u Update existing archive-v generate verbose output on standard output-F Specify archive file name-M include manifest information fromSpecified manifest file-N Perform Pack200 normalization after creating aNewArchive-e Specify application entry point forstand-alone application bundled to an executable jar file-0store only, use no ZIP compression-P Preserve Leading'/'(absolute path) and".."(Parent directory) components fromfile Names-M DoNot create a manifest file forThe entries-I generate index information forThe specified jar files-C change to the specified directory and include the following fileif any file isA directory then it isprocessed recursively. The manifest file name, the archive file name and the entry point name arespecifiedinchThe same order asThe'm','F'and'e'flags. Example1: To archiveclassfiles into an archive called Classes.jar:jar CVF Classes.jar Foo.classBar.classExample2: Use of an existing manifest file'mymanifest'and archive all the filesinchThe foo/directory into'Classes.jar': Jar CVFM Classes.jar mymanifest-C foo/.

2) The first way jar-cvf./class2json.jar./com (This method does not work)

Class2json.jar is the jar package name. /com the  file into the jar package.

The contents of the jar package are as follows:

Which meta-inf/manifest. MF is automatically generated as follows: There is no additional jar package and the main class

1.0 Created 1.8. 0_181 (Oracle Corporation)

The command line looks like this: because we did not specify the main class to run, Java-jar Class2json.jar failed because the main class could not be found

3) The second way jar-cvf./class2json.jar./com (This method does not work)

Jar command to hit 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.