[Switch] Introduction and difference of jar package and war package, jarwar package
The JavaSE program can be packaged into a Jar package (J can be understood as Java), while the Java Web program can be packaged into a war package (w can actually be understood as Web ). Release the war file to the webapps directory of Tomcat. Tomcat automatically decompress the war package at startup.
JAR (Java Archive, Java Archive) is a platform-independent file format that allows many files to be combined into a compressed file. The JAR file created for the J2EE 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 release, but also for deployment and encapsulation of libraries, components, and plug-in programs, and can be directly used by tools such as compilers and JVM. JAR contains special files, such as manifests and deployment descriptor, to indicate how the tool handles specific JAR.
If a Web application has many directories and files, it is not convenient to deploy the Web application on another machine, we can package a Web application into a Web archive (WAR) file. This process is similar to the process of packaging a Java class file into a JAR file. The WAR file can be used to publish Servlet files and related resources together. In this process, the Web application is not deployed according to the directory hierarchy, but the WAR file is used as the deployment unit.
A war file is a Web application. Creating a WAR file is to compress the entire Web application (excluding the root directory of the Web application hierarchy) and specify a. war extension. Next we will package the Web application in Chapter 1 into a WAR file, and then release
It should be noted that although the WAR file and JAR file are in the same format and are created using the jar command, in terms of its application, WAR files and JAR files are fundamentally different. The purpose of a JAR file is to encapsulate classes and related resources into compressed archive files. For a WAR file, a WAR file represents a Web application, it can contain Servlets, HTML pages, Java classes, image files, and other resources that comprise Web applications, not just archive files of classes.
When should we use WAR files? WAR files are not suitable for use in the development phase, because in the development phase, you often need to add or delete the content of Web applications and update Servlet files. After each change, reestablishing a WAR file is a waste of time. In the product release stage, it is appropriate to use the WAR file, because at this time, there is almost no need to make any changes.
In the development phase, Servlet Source files are usually put under the src subdirectory of the Web application directory to distinguish them from Web resource files. When creating a WAR file, you only need to remove the src directory from the Web application directory to package it.