Home> Java> javaTutorial> body text

What is the difference between jar package and war package in java?

青灯夜游
Release: 2019-04-23 10:58:02
Original
7635 people have browsed it

In Java, jar packages and war packages can essentially be regarded as compressed files, so what are the differences between them? The following article will take you to understand jar packages and war packages, and introduce the differences between jar packages and war packages. I hope it will be helpful to you. [Video tutorial recommendation:Java tutorial]

What is the difference between jar package and war package in java?

jar package

Simple To put it bluntly, JAR (Java Archive) is a package file format. JAR files have a .jar extension and can contain libraries, resources, and metadata files.

Essentially, it is a compressed file that contains compressed versions of .class files and compiled Java libraries and application resources.

For example, here is a simple JAR file structure:

META-INF/ MANIFEST.MF com/ baeldung/ MyApplication.class
Copy after login

where the file Xiaohong in META-INF/manifest.mf may contain additional metadata about the files stored in the archive.

We can use the jar command or tools such as maven to create jar files.

war package

war represents a web application archive or web application resource. These archive files have .war extension and are used to package web applications that we can deploy on any servlet/jsp container.

The following is an example of the layout of a typical WAR file structure:

META-INF/ MANIFEST.MF WEB-INF/ web.xml jsp/ helloWorld.jsp classes/ static/ templates/ application.properties lib/ // *.jar files as libs
Copy after login

Internally, it has a META-INF directory that holds useful information about the web archive in manifest.mf . The META-INF directory is private and cannot be accessed from the outside.

On the other hand, it also contains the WEB-INF public directory, which contains all static web resources, including HTML pages, images, and JS files. Additionally, it contains web.xml files, servlet classes and libraries.

We can build the war file using the same tools and commands as when building the JAR.

The difference between jar package and war package in java

1. Different file extensions

JARs have a .jar extension, while WAR files have a .war extension.

2. Different purposes and modes of operation

JAR files allow us to package multiple files in order to use them as libraries, plug-ins or any type of application. On the other hand, WAR files are only used for web applications. A war package can be understood as a web project, which contains everything about the project. .

3. The structure of the file is also different

We can create a JAR with any desired structure. In contrast, WAR has a predefined structure of WEB-INF and META-INF directories.

The above is the detailed content of What is the difference between jar package and war package in java?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!