JAR usage (reproduced)

xiaoxiao2021-03-06  70

JAR usage:

Usage: jar {ctxu} [vfm0mi] [jar- file] [manifest- file] [-c directory] file name ...

Option:

-c Create a new archive

-t lists the list of archived content

-x Expand Named (or all) files in the archive

-u Update existing archive

-v generation detailed output to standard output

-f specified archive file name

-m includes indicated information from the indicated file

-0 storage mode; unused zip compression format

-M does not generate a list of all items (Manifest] file

-i generate index information for the specified JAR file

-C changes to the specified directory and contains the following files:

If a file name is a directory, it will be processed.

The list (Manifest) file name and archive file name need to be specified, press the same order as specified by 'm' and 'f' flags.

Example 1: Archive two Class files into an archive file called 'classes.jar':

Jar cvf classes.jar foo.class bar.class

Example 2: Archive all files in the foo / directory in an archive file named 'Classes.jar' with an existing list (MANIFEST) file 'mymanifest'.

JAR CVFM Classes.jar mymanifest -c foo /.

Try to see a small example:

We only have a HelloWorld as follows:

Public class helloworld {

Public static void main (String [] args) {

System.out.Println ("Hi, Hello World!");

}

}

Save this Java file to the C drive with the directory, OK, next,

Under the previously opened command prompt (jump to the C disk prompt), we entered Javac HelloWorld.java, then continue to enter: jar cvf hello.jar HelloWorld.class, go to your C drive after entering bus, What happens, there is no mistake hello.jar.

Basic steps we all know now, you can try it with the difference in the parameters behind JAR, what changes have changed.

Then we look at how to run our JAR package.

Before entering the topic, you have to open our JAR bag to see, what happened, Meta-INF directory? Take a look at what is it, and there is a manifest.mf file? Use the text editor (I am UltraEdit) to open it:

Manifest-Version: 1.0

Created-by: 1.4.2 (Sun Microsystems Inc.)

That's it. Here we modify it, plus: main-class: helloworld (in the third line). This is the class we wrote before, which is our entrance class. Also,

Manifest-Version: 1.0

Created-by: 1.4.2 (Sun Microsystems Inc.)

Main-class: HelloWorld

Next, we execute in the command prompt:

Jar umf manifest.mf app.jar (should be hello.jar)

This way we used our own manifest.mf files to update the original default. You may wish to go in and see if you add main-class: helloworld. (Is it, why didn't I try it out, prompt java.io.filenotfoundexception: manifest.mf (the system can't find the specified file) What is going on?) OK, this last step, to verify everything we do, Enter: in the command prompt:

Java -jar Hello.jar (execution)

What have you, Hi, Hello World!

Let's take a look at the JAR file in Tomcat, pay attention: We can't use the JAR in this format in Tomcat, and change the WAR format. It is specifically used for web applications. In fact, the whole process is basically similar to JAR. Similar of:

Prepare the resources we have to pack.

Find the WebApps directory stored in Tomcat, come to it, create a new folder, name Hello, then enter the new web-INF folder, then enter the new Classes folder, then we will also sell our only servlet, HelloWorld.java Put here, build a file web.xml under the same level as the class content. OK, we have initially established a simple web application.

This is HelloWorld.java:

Import java.io. *;

Import javax.servlet. *;

Import javax.servlet.http. *;

Public class helloworld extends httpservlet {

Public void doget (httpservletRequest Req, httpservletResponse res)

Throws servletexception, ioException {

Res.SetContentType ("text / html");

PrintWriter out = res. maxwriter ();

OUT.PRINTLN ("");

OUT.PRINTLN ("");

OUT.PRINTLN ("");

OUT.PRINTLN ("Hello, World!");

OUT.PRINTLN ("");

}

} // end here!

Compile it. Here is web.xml:

Hello

HelloWorld

Hello

/ helloworld

In the command prompt, enter the previously created Hello directory, perform JAR CVF Hello.war *, we get Hello.war. Copy it into the WebApps directory, OK, come and see the last step, open the server.xml of the Tomcat's directory confes, join:

Datual! Run it, start Tomcat, and enter http: // localhost: 8080 / hello / helloWorld, is there?

Finally, if you want to use Ant to complete the above packages, let you know:

For JAR. In Build.xml,

For WAR,

Ok, so much, I hope to help you. :)

supplement:

JAR basic operation:

1. Create a JAR file

JAR CF JAR-FILE Input-file (s)

C --- Want to Create a Jar File.

F --- Want The Output to Go to a File Rather Than To Stdout.

EG: 1) jar cf myjar.jar query_maintain_insert.htm

2) JAR CVF myjar.jar query_maintain_insert.htm

v - products verbose (detailed) Output.

3) JAR CVF myjar.jar query_maintain_insert.htm mydirectory

4) JAR CV0F myjar.jar query_maintain_insert.htm mydirectory

0 - Don't Want The Jar File to Be Compressed.

5) Jar cmf manifest.mf myjar.jar yahh.txt

M --- used to include manifest information from an existing manifest file.6) jar cmf manifest.mf myjar.jar yahh.txt

M --- The Default Manifest File Should Not Be Producesd.

7) JAR CVF myjar.jar *

* --- Create All Contents in Current Directory.

2. Look at the JAR file

Jar TF JAR-FILE

T --- Want to View The Table of Contents of The Jar File.

EG: 1) JAR VFT Yahh.jar

v - products verbose (detailed) Output.

3. Extract JAR files

Jar Xf Jar-file [Archived-file (s)]

X --- Want to Extract Files from The Jar Archive.

EG: 1) JAR XF Yahh.jar Yahh.txt (only extracts Yahh.txt)

2) jar Xf yahh.jar alex / yahhalex.txt (only files under the directory Alex Yahlex.txt)

3) JAR XF Yahh.jar (extract all files or directories in this jar package)

4. Modify the manifest file

JAR CMF MANIFEST-Addition Jar-file Input-file (s)

M --- Used to include manifest information from an existing manifest file.

5. Update the JAR file

Jar uf jar-file input-file (s)

u --- Want to update an existing jar file.

转载请注明原文地址:https://www.9cbs.com/read-94751.html

New Post(0)