Home » Java » Java war vs. jar – what is the difference?

Java war vs. jar – what is the difference?

Posted by: admin November 2, 2017 Leave a comment

Questions:

What is the difference between a .jar and a .war file? Is it only the file extension or is there something more?

Answers:

From Java Tips: Difference between ear jar and war files:

These files are simply zipped files
using the java jar tool. These files are
created for different purposes. Here
is the description of these files:

  • .jar files: The .jar files contain
    libraries, resources and
    accessories files
    like property files.

  • .war files: The war file contains
    the web application
    that can be
    deployed on any servlet/jsp
    container. The .war file contains jsp,
    html, javascript
    and other files
    necessary for the development of web
    applications.


Official Sun/Oracle descriptions:


Wikipedia articles:

Questions:
Answers:

A .war file has a specific structure in terms of where certain files will be. Other than that, yes, it’s just a .jar.

Questions:
Answers:

You add web components to a J2EE application in a package called a web application archive (WAR), which is a JAR similar to the package used for Java class libraries. A WAR usually contains other resources besides web components, including:

  • Server-side utility classes (database beans, shopping carts, and so on).
  • Static web resources (HTML, image, and sound files, and so on)
  • Client-side classes (applets and utility classes)

A WAR has a specific hierarchical directory structure. The top-level directory of a WAR is the document root of the application. The document root is where JSP pages, client-side classes and archives, and static web resources are stored.

(source)

So a .war is a .jar, but it contains web application components and is laid out according to a specific structure. A .war is designed to be deployed to a web application server such as Tomcat or Jetty or a Java EE server such as JBoss or Glassfish.

Questions:
Answers:

The main difference between a JAR and a WAR is that a JAR is not really a single purpose format, while a WAR is. With a JAR file, you can package lots of different things. Usually you package up Java classes, but you could put pretty much anything into a JAR file, and you can create JARs that have whatever files and directory formats you want. For instance, Oracle (at least in 8.1.x) actually uses JAR files to distribute the Oracle software on the install CDs, and IBM uses them to distribute an installable version of the documentation for WebSphere. Technically you can put JSP pages, HTML pages, servlet classes, etc. in a JAR, but you generally don’t — you use a WAR.

WAR files are JAR files with a specific format. This format is defined in the servlet spec (which you can look at on the java.sun.com site). Essentially, the WAR file is a standard format for web applications that has specific directories and specific files. This includes a WEB-INF directory, a WEB-INF/web.xml file used to describe the application, a WEB-INF/lib directory for JAR files used by the application, and a WEB-INF/classes directory for class files that aren’t distributed in a JAR. You would put the pages (JSPs and HTML) in the WAR as well. Then, you can distribute your application as one file, instead of as a collection of images, HTML pages, and Java classes.

Questions:
Answers:

A .war file is a Web Application Archive which runs inside an application server while a .jar is Java Application Archive that runs a desktop application on a user’s machine.

Questions:
Answers:

A war file is a special jar file that is used to package a web application to make it easy to deploy it on an application server. The content of the war file must follow a defined structure.

Questions:
Answers:

.jar and .war are both zipped archived files.
Both can have the optional META-INF/MANIFEST.MF manifest file which hold informative information like versioning, and instructional attributes like classpath and main-class for the JVM that will execute it.

.war file – Web Application Archive intended to be execute inside a ‘Servlet Container’ and may include other jar files (at WEB-INF/lib directory) compiled classes (at WEB-INF/classes (servlet goes there too)) .jsp files images, files etc.
All WAR content that is there in order to create a self-contained module.

Questions:
Answers:

Basicly both compressed archives. war is used for web application with a specific directory structure.

Questions:
Answers:

EAR is an Enterprise Application archive and may contain ejb JAR files, WAR files, and RAR (connector) files. They may also contain third-party libraries – but you have to know how to manipulate the Java extension facilities (e.g. MANIFEST.MF Class-Path directive) to make that work well.

WAR is an Web Application archive and contains JSPs, “normal” HTTP served files (HTML, images, etc.), servlets, tag libraries.

JAR is the “normal” Java Application archive, but in this context it usually contains EJBs instead of code libraries or runnable (e.g. from outside an application container) applications.

Questions:
Answers:

war and jar are archives for java files. war is web archive and they are running on web server. jar is java archive.

Questions:
Answers:

Jar files (files with a .jar extension) are intended to hold generic libraries of Java classes, resources, auxiliary files, etc.Whereas War files (files with a .war extension) are intended to contain complete Web applications. In this context, a Web application is defined as a single group of files, classes, resources, .jar files that can be packaged and accessed as one servlet context.