Have you heard of JAR files? Or strange! Ok, it doesn't matter, this is our first stop: package release. Why do you have this stuff? First, this is the full name of JAR: Javatm Archive (JAR) File, yes, is the Java archive file. This is a bit similar to the zip file, think about it, what is it?
! ? Yes, it is to compress, put our original zero-scattered things, reorganize, all these purposes only: convenient! Ok, don't take care of how he is compressed, our focus is what we have to be compressed (input), and it is compressed into what (output), which will be released (deploy). Then our input (to compress something) is mainly the class file, there is also auxiliary resource (this may have pictures, JSP files, HTML files, etc.). JAR technology already exists in the JDK1.1 version, which has been enhanced in 1.2. Let's say the benefits of JAR, this is the official description: safe, quick download, compression, hunting bag, version of the package, can be combined. Said so much, we are now implementation. 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
Compressed Format-M Not produces a list of all items (Manifest) file -i to generate index information -c to change to the specified directory for the specified JAR file, and contain 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 to a archive file called 'classes.jar' : JAR CVF CLASS.JAR FOO.CLASS BAR.CLASS Example 2: Archive all files in the foo / directory into an archive file named 'Classes.jar' with a list of Foo / Directory with an existing list (Manifest) file. : 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 under 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, what is much, 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.) 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"?>
">