Differences Between Jar and War
The full form for "JAR" files is "Java Archive" files; whereas the full form of "WAR" files is "Web Application Archive" files.
The main difference between JAR files and WAR files is that one can package many different things in JAR files.
It not only packages the java Java classes, but a lot of other things can be packaged as well. However, WAR files are specifically for web applications.
The JAR files are packaged with a .jar extension; whereas WAR files are packaged with a .war extension.
The Jar files packaged with java classes with functionality; whereas web modules are packaged as WAR files which contain JSP files, Servlet class files, supporting files, GIF, and Html. But Now In spring boot applications Jar files contains JSP files, Servlets, images and Html pages, and the web server also.
We can create a Jar file using the jar command or using a maven. please refer how to create a Jar file
now we see the detailer description for both.
JAR Packaging
The jar file is a zip file with .java extension containing the compressed versions of .class files and resources of compiled Java libraries and applications.
META-INF/
MANIFEST.MF
com/
bala/
app/
MyApp.class
The META-INF/MANIFEST.MF file may contain additional information about the files stored in the archive.
If we want to run a java application, we need to use the command on command prompt or shell as
java -jar myapp.jar
If we want our jar in some other projects then we need to publish the jar file to nexus or maven or other repositories or else we can make reference in our project.
War Packaging
The war file is a zip file with .war extension containing the compressed versions of .class files and other resources like JSP files, Servlet class files, supporting files, GIF, and HTML. It is a compiled version of Java libraries and applications.
If we want run java files or web application inside the jar we need to deploy the war file inside a Web Containers like Apache Tomcat, Jboss, Jetty, etc.
The web application structure is like
META-INF/
MANIFEST.MF
WEB-INF/
web.xml
jsp/
index.jsp
welcome.jsp
classes/
static/
templates/
application.properties
lib/
// *.jar files as libraries
META-INF is a private directory and can't be accessed from the outside.
WEB-INF is a public directory contains all the static web resources, including Html pages, images, js, CSS files, and other application related files.
The development o spring boot framework makes this difference as minimal as, In Spring boot application we can create a Jar or war. It depends on your application specification/requirement whether you want jar file or war file.
And When the application can be deployed using an in-build server inside Jar file, no need to set up an external server.
In Modern MicroServices Architecture most of Web or Standalone applications deployed inside containers as a jar file.
That's it !!!. We have seen the differences between Jar and War in Java.
0 Comments
Post a Comment