How to build your own. jar file

Source: Internet
Author: User



1 What is the. jar file
The suffix of the Java archive (Java Archive) file is. jar. The jar file format is based on the popular ZIP file format. Unlike the zip file format, jar files are not only used for compression and publishing, but are also used to deploy and encapsulate libraries, components, and plug-ins, and can be used directly by tools such as compilers and JVMs, including special files such as manifest and deployment descriptors in jars. Used to indicate how a tool handles a particular jar.

2 working in Eclipse
2.1 Directly Select the package name you want to package multiple with CTRL + SELECT
2.2 Right-click Java->jar file->export
2.3 Select a directory to store after packaging
[Note that this package is all Java source code]

3 package in DOS for Windows
  3.1 First, you must ensure that the Jar Packaging tool   install JDK
  3.2 First Enter the jar to see the relevant command information
F:\1>jar
Usage: jar {Ctxui}[vfmn0me] [jar-file] [manifest-file] [entry-point] [-c dir] files ...
Options:
   -c  Create a new profile
   -t  list the file directory
   -x  Extract specified (or all) files from the archive
   -u  Update existing archives
   -v  generate verbose output in standard output
    -f  Specify the file file name
   -m  contains inventory information from the specified manifest file
   -n  execute Pack200 After creating a new file Normalize
   -e  for standalone applications bound to executable jar files
        Specify application entry points
    -0  store only; do not use any ZIP compression
   -m  do not create an entry for the manifest file
   -i& nbsp Generates index information for the specified jar file
   -c  changes to the specified directory and contains the following files
If any file is a directory, it is recursively processed. The
manifest file name, the specified order of the file file name and entry point name
is the same as the specified order for ' m ', ' f ' and ' e ' tags.

Example 1: Archive two class files to a file named Classes.jar:
Jar CVF Classes.jar Foo.class bar.class
Example 2: Using the existing manifest file ' Mymanifest ' and
Archive all files in the foo/directory to ' Classes.jar ':
Jar CVFM Classes.jar mymanifest-c foo/.
You can see that the command prompt also gives two examples.
3.3 Next, select command options as required
4 How to fix the path name as the top-level package name in the package library after packaging
[Here I am just having this problem, and the solution, share it to everyone]
4.1 First cut the directory to the file directory to be packaged. For example, one of my class files The full directory is:
F:/1/com/luise/demo1/test.class
I switched the directory to f:/1/.
4.2 Input Command:
F:\1>jar CVF test.jar-c./.
Where./is under the current directory; is all files in the current directory
4.3 OK, success.
5 use
5.1 In the project, copy the. jar file directly under the Libs folder without creating a new one yourself.
5.2 Select the imported. jar file, and the ADD to build path, right-click Build path, will appear with a reference Library folder.
5.3 Can be used as you normally would with a class in a jar.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

How to build your own. jar file

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.