First open the command prompt (win2000 or execute the cmd command in the running basket, Win98 is a DOS prompt), enter jar -help, then enter! If you already have JDK1.1 or above version on your disc), see what :
Usage: jar {ctxu} [vfm0mi] [jar- file] [manifest- file] [-c directory] file name ...
Option:
-c Create a new archive -T list of the list of archive contents -X expands Named (or all) file -U update existing archive -V generation detailed output to standard output -f specified archive file name -m includes indicated information -0 storage mode from indicated files; unrequited lists that do not generate all items (MANIFEST) file-M change to the specified Directory-C to change to the specified directory. And contain 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 into a archive file named 'Classes.jar' with an archive file that exists in the Foo / Directory: JAR CVFM Classes.jar mymanifest -c foo /.
Try to see a small example: We have only one helloworld, as follows:
Public class helloworld {public static void main (string [] args) {system.out.println ("Hi, Hello World!");}}
I save this Java file to the C drive, 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. That is, 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
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. OK, this last step, to verify everything we do, type in the command prompt: java -jar hello.jar (execution)
What have you appeared, - hi, hello world! Let's take a look at the JAR file release in Tomcat, pay attention: We can't use the JAR in this format in Tomcat, and change the WAR format, which is specifically used for web applications. In fact, the whole process is basically similar to JAR:
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.
Under 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 in the Tomcat's directory confes, join: reloadable = "true" /> Datual! Run it, start Tomcat, and enter http: // localhost: 8080 / hello / helloWorld, is there?
Ok, so much, I hope to help you.
Supplement: ############
JAR basic operation:
############
1. Create 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 --- Produces 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 Products. 7) JAR CVF Myjar.jar * * --- Create All Contents in Current Directory. 2. View 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 File 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 Al EX / YAHHALEX.TXT (only files under directory Alex Yahhalex.txt) 3) JAR XF Yahh.jar (extract all files or directories in this jar package) 4. Modify Manifest file JAR CMF Manifest-Addition Jar-file Input -file (s) m --- used to include manifest information from an existing manifest file.5. Update JAR file
JAR UF JAR-FILE INPUT-FILE (S) U --- Want To Update An Existing Jar File.
Very simple, I will understand the post, my brother