Open the command prompt (Win2000 or execute the CMD command in the run box, Win98 is a DOS prompt), enter JAR Chelp, 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 archived contents -X Expand Named (or all) file -U update existing archive -V generation detailed output to standard output -f specified archive file name -M contains flag information from the indicate file - 0 only storage method; unused zip compression Format -M does not generate a list of all items (Manifest) file-i generates index information -c to change to the specified directory for the specified JAR file, and contains the following file: If a file name is a directory, it will be recursively 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 the archive file called 'classes.jar' : JAR CVF CLASS.JAR FOO.CLASS BAR.CLASS Example 2: Archive all files in the foo / directory into a archive file named 'Classes.jar' with an existing list (manifest) file 'mymanifest'. JAR CVFM Classes.jar mymanifest -c foo /. Try to see: We have only one 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 below 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 disk after entering bus, there are more, true hello.jar. Base This steps we all know now, you can try itself 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.) is like this. 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 (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: java -jar hello.jar (execution) What, Hi, Hello World! Let's take a look at the JAR file release in Tomcat, pay attention: We can't use JAR in this format in Tomcat, To change the WAR format, it is specifically used for web applications. In fact, the whole process is basically similar to JAR: Pre-prepare 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. max, out.println (""); out.println (""); out.println (""); Out.println ("Hello , World! "); Out.println (" ");}} // end here!
The following is Web.xml: XML Version = "1.0" Encoding = "UTF-8"?>