The difference between Java-jar and war packages

The difference between jar package and war package:


1. War is a web module, which needs to include WEB-INF, which is a WEB module that can be run directly; jar generally only includes some class files, which can be run with the java command after the Main_class is declared.
2. A war package is a web application, usually a website, packaged and deployed in a container; a jar package usually refers to a common class during development, and is packaged for easy storage and management.
3. war is a web application format proposed by Sun, and it is also a compressed package of many files. The files in this package are organized according to a certain directory structure; the classes directory contains compiled Servlet classes and other classes (such as JavaBean) that Jsp or Servlet depends on can be packaged into jars and placed in the lib directory under WEB-INF.
4. The JAR file format is based on the popular ZIP file format. Unlike ZIP files, JAR files are used not only for compression and distribution, but also for deployment and packaging of libraries, components, and plug-ins, and can be used directly by tools like compilers and the JVM.

Format features:


Security JAR file contents can be digitally signed. This way, a tool that recognizes the signature can selectively grant you software security privileges that other files cannot, and it can detect if the code has been tampered with.
Reduced download time If an applet is bundled into a JAR file, the browser can download the applet's class files and associated resources in one HTTP transaction, rather than opening a new connection for each file.
Compression: The JAR format allows you to compress files for storage efficiency.
Transport platform extensions: The Java Extensions Framework (Java Extensions Framework) provides a way to add functionality to the Java core platform, and these extensions are packaged in JAR files (Java 3D and JavaMail are examples of extensions developed by Sun).
WAR file: It is a web application. To create a WAR file is to compress the entire web application (excluding the root directory of the web application hierarchy) and specify a war extension.

Conditions established:


Need to establish the correct directory hierarchy for the web application.
Create a WEB-INF subdirectory, and create two subdirectories, classes and lib, under this directory.
Put the Servlet class file in the WEB-INF\classes directory, and put the Java class library file (that is, the JAR file) used by the Web application in the WEB-INF\lib directory.
Put JSP pages or static HTML pages under the context root path or its subdirectories.
Create a META-INF directory, and create a context.xml file under this directory.

Guess you like

Origin blog.csdn.net/wuds_158/article/details/132211254