The Javase program can be packaged as a jar package (J can actually be understood as Java), and the Javaweb program can be packaged into a war package (W can actually be understood as the web). Then publish the war to Tomcat's WebApps directory, and Tomcat will automatically unzip the war package at startup.
The JAR (Java Archive,java archive) is a platform-independent file format that allows many files to be combined into a single compressed file. The JAR file created for the Java EE application is an EAR file (Enterprise JAR file).
The JAR file format is based on the popular ZIP file format. Unlike ZIP files, 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. The jar contains special files, such as manifests and deployment descriptors, to indicate how the tool handles a particular JAR.
If a Web application has many directories and files, it is not convenient to deploy the Web application to another machine, and we can package the Web application as a Web archive (WAR) file, similar to the process of packaging a Java class file into a jar file. The war file allows you to centralize the Servlet class files and related resources for publishing. In this process, the Web application is not deployed according to the directory hierarchy, but instead uses the war file as a deployment unit.
A war file is a Web application that creates a war file that compresses the entire Web application (excluding the root directory of the Web application hierarchy) and specifies a. war extension. Next we package the 2nd Web application into a war file and then publish
Note that although the file format of the war file and the jar file is the same and is created using the Jar command, the war file and the jar file are fundamentally different for their application. The purpose of the jar file is to encapsulate classes and related resources into a compressed archive, and for a war file, a war file represents a Web application that can contain servlets, HTML pages, Java classes, image files, and other resources that make up a Web application. Rather than just the archive of the class. The files in the war package are organized according to a certain directory structure. Depending on the root directory, there are HTML and JSP files, or directories containing both files, plus the Web-inf directory. Typically, the Web-inf directory contains a Web. xml file and a classes directory, and Web. XML is the application's configuration file, while the classes directory contains the compiled servlet classes and JSPs, or other classes (such as JavaBean) that the servlet relies on. Often these dependent classes can also be packaged into jar packages placed under the Lib directory under Web-inf.
Jar Package: Typically a generic class to be referenced at development time, which is made into a package for easy storage management. In short, a jar package is a class that someone else has already written, and then packages the classes. These jar packages can be introduced into your project and can be used directly from the classes and attributes in these jar packages, which are typically placed in the Lib directory.
When should we use the war file? It is not appropriate to use the war file during development, because in the development phase it is often necessary to add or remove content from the Web application, update the servlet class files, and after each change, it is a waste of time to re-establish the war file. In the product release phase, it is more appropriate to use the war file because at this point, there is little need to make any more changes.
In the development phase, we typically place the servlet source file under the SRC subdirectory of the Web application directory to differentiate it from the Web resource file. When you create a war file, you only need to remove the SRC directory from the Web application directory to package
If you want to generate a war file: You can use the following command: JAR-CVF Web1.war *
If you want to see what files are in Web1.war, you can use the command: JAR-TF Web1.war
If you want to extract the Web1.war file directly, you can use the command: JAR-XVF Web1.war
In addition, you can use the WinRAR software to select the Zip compression method, and the compressed file suffix to the war can be compressed to generate a war file, also use the WinRAR software can forcibly open the war file, or forcibly extract the war file
The difference between using the jar command and the WinRAR software is that the Metainf folder, which contains the MANIFEST.MF file, is generated while the file is compressed.
This article is from the "Dream to Reality" blog, please be sure to keep this source http://lookingdream.blog.51cto.com/5177800/1951192
Introduction and differences of jar packages and war packages