Jar package and War Project labeled package introduction and the difference

Introduction 1.jar package

JAR (Java Archive, Java archive files) are platform-independent file format, which allows to combine many files into a single compressed file. JavaSE program can be packaged into a Jar package (J in fact, it can be understood as a Java).

JAR file format based on the popular ZIP file format. The difference is that with ZIP files, JAR files, not only for compression and release, but also for packaging and deploying libraries , components and plug-ins , and can be used directly as compilers and tools such JVM. Special contained in the JAR file, and manifests as deployment descriptors, the tool used to indicate how to handle specific JAR.

In simple terms, jar package is that some people have written class, then to package these classes. These jar package can be introduced into your project, you can use these jar package classes and properties directly, these are generally placed in the jar package lib directory.

Introduction 2.war package

It is a war can run a web module, commonly used for the site, labeled deploy the package to the container. To Tomcat, the package will be placed in its war \ webapps \ directory, then start Tomcat, this package will automatically extract, equivalent released.

war package is a web application format proposed by Sun, and the jar is similar to a lot of compressed files. war files in the package according to a certain directory structure to organize. The root directory contains the html and jsp file or directory containing the two files, in addition to WEB-INF directory. In generally contain a WEB-INF directory and a file web.xml classes directory, web.xml is the application configuration file, the directory contains the classes compiled servlet class and jsp, servlet, or other classes depends ( such as JavaBean). Often these classes depends jar packages may be packaged into the lib directory under WEB-INF.

In simple terms, the WAR program package is JavaWeb play package , war package which includes write code compiled into class files, depending on the package configuration file, all pages of the site, including html, jsp and so on. A war package can be understood as a web project, which is something all projects.

3. difference:

①WAR file represents a Web application.

②JAR is kind of archive.

If a Web application directories and files is very large, then this Web applications deployed on another machine, it is not very convenient, when the Web application can be packaged as a Web archive (WAR) file, this process and to package Java class files into a JAR file process is similar. Using the WAR file, you can focus Servlet class files and associated resources together to publish. In this process, Web applications, it is not in accordance with the directory hierarchy be deployed, but the WAR file to use as a deployment unit.

A WAR file is a Web application, build a WAR file, is to put the entire Web application (not including the root directory hierarchy Web applications) compression up to specify a .war extension.

Note that, although the file format WAR and JAR files are the same, and are created using the jar command, but its applications, WAR and JAR files are fundamentally different. The purpose is to JAR file class and associated resources packaged into a compressed archive file , whereas for WAR files, a WAR file represents a Web application , it can contain Servlet, HTML pages, Java classes, image files, and other resources make up a Web application, rather than just archive the class.

So when should use the WAR file? In the development stage is not suitable for use WAR file, because during the development phase, often need to add or delete the contents of a Web application, update the Servlet class files, and after each change, to re-establish WAR file It is a waste of time thing. In the product release phase, using the WAR file is more appropriate , because at this time, almost do not need to do anything to change the.

During the development phase, we usually Servlet source file into the src subdirectory of the Web application directory, and Web resources in order to differentiate file. In establishing the WAR file and need to be removed from the src directory Web application directory, you can pack up.

4. Use of item Jar package, War packet

Jar包:

Directly uploaded to the server can be used

War package:

Tomcat's webapps needs to be placed in, rely on container operation

Published 143 original articles · won praise 40 · views 20000 +

Guess you like

Origin blog.csdn.net/LemonSnm/article/details/103939518