Introduction and differences of jar packages and war packages

Source: Internet
Author: User

Reprint: http://blog.csdn.net/u012110719/article/details/44260417

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.

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

Introduction and differences of jar packages and war packages

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.