Difference between jar and war in Java
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:
- The J2EETM Tutorial: Web Application Archives
- The Java Archive (JAR) File Format: The Basics
Wikipedia articles:
- WAR file format (Sun)
- JAR file
Differences between jar and war in Spring Boot?
Spring Boot can be told to produce a 'fat JAR' which includes all of your module/service's dependencies and can be run with java -jar <your jar>
. See "Create an executable JAR with Maven" here.
Spring Boot can also be told to produce a WAR file, in which case you'll likely choose to deploy it to a web container such as Tomcat or Jetty.
Plenty more details on Spring Boot deployment here.
JAR vs WAR file specification
From a conceptual point of view:
A jar
typically represents a single library which can be used and may or may not have dependencies.
But the idea is that a specific functionality can be provided as a library in a jar
.
A war
is an application by itself and as such it should include all the dependencies
Difference between Jar and War packaging with embedded Tomcat
Generally speaking, when you're using an embedded container, you should stick to the defaults and build a jar file.
There are, however, two exceptions to that rule:
- You want to use JSPs. In that case you'll need to use war packaging as Tomcat's JSP support is tightly coupled to the layout of a war file.
- You want to have the option of also deploying your application to a standalone container or app server.
.war vs .ear file
From GeekInterview:
In J2EE application, modules are packaged as EAR, JAR, and WAR based on their functionality
JAR:
EJB modules which contain enterprise java beans (class files) and EJB deployment descriptor are packed as JAR files with .jar extensionWAR:
Web modules which contain Servlet class files, JSP Files, supporting files, GIF and HTML files are packaged as a JAR file with .war (web archive) extensionEAR:
All the above files (.jar and .war) are packaged as a JAR file with .ear (enterprise archive) extension and deployed into Application Server.
Related Topics
How Cancel the Execution of a Swingworker
Sorting Arraylist in Alphabetical Order (Case Insensitive)
How Do Hashcode() and Identityhashcode() Work at the Back End
How to Set Specific Java Version to Maven
Maven Error: Could Not Find or Load Main Class Org.Codehaus.Plexus.Classworlds.Launcher.Launcher
Getting Java.Sql.Sqlexception: Operation Not Allowed After Resultset Closed
In Java, What Are the Advantages of Streams Over Loops
What Is the Purpose of Flush() in Java Streams
How to Select a Dropdown Value in Selenium Webdriver Using Java
How to Import Org.Openqa.Selenium.Webdriver Using Selenium and Java 11
Whitespace Matching Regex - Java
Converting Roman Numerals to Decimal
Java Synchronized Method Lock on Object, or Method