Introduction
Nowadays, there are many frameworks available. Still, some of them are not lightweight, so unhandy to use, and for those modules, the packaging is a big issue.
It's where the spring framework comes into view. It is a very light framework, and along with that, it also provides predefined templates JPA, Hibernate, JDBC, etc., and it provides packaging and that we are going to study further in this blog.
File Formats of Packaging
Modules are packed as WAR, JAR, and EAR in the J2EE application. In J2EE, these are the compressed file formats.
Spring boot packaging provides a jar file as its default mode of packaging modules.
WAR
It stands for Web Archive. These files represent web applications. The Web modules, HTML files, JSP files, JavaScripts, servlet classes, etc., all are present with the .war extension but packaged as a JAR file. It also contains a unique directory named WEB-INF.
Spring mainly focuses on JAVA as War concentrates primarily on the Web, so the war module loads into the web container of the JAVA application server. And this application server of java has two containers: the EJB container and the Web container.
The EJB container hosts the EJB API-based enterprise java beans. All the EJB modules are required to be packaged as a JAR file. In the META_INF folder, it contains an ejb-jar.xml file.
The Web Container hosts servlet API and JSP-based web applications. The web container requires the web module to be packaged as a WAR file. There is a web.xmlv file in the WEB-INF folder that is a WAR file special JAR file.
Advantages of using a WAR file
- The MVC structure supports WAR files.
- The version identification of the deployed application becomes effortless.
- All J2EE containers support WAR files.
- Easy deployment and testing of web applications.
Disadvantages of using a WAR file
- : The source code must be repackaged and deployed in development whenever you change the source code.
META-INF/
MANIFEST.MF
WEB-INF/
web.xml
JSP/
HelloWorld.JSP
classes/
static/
templates/
application.properties
lib/
// *.jar files as libs
JAR
JAR stands for Java Archive. An Enterprise Java Bean(EJB) Module that contains a manifest, an EJB deployment descriptor(XML file) and class files(bean files) with an extension .jar are packaged as JAR files.
Software developers use this to distribute various metadata and Java classes.
A JAR file is a file that encapsulates a manifest, a descriptor, and one or more Java classes. The lowest level of the archive is JAR. For packaging client-side and EJb java applications in J2EE, JAR is used, and it makes the deployment easy.
Advantages of using a JAR file
- The enhancement of technology provides a digital signature.
- It is effortless to maintain, handle, create.
- It is used for its compression abilities.
- Packaging reduces the burden of managing multiple modules burden.
Disadvantages of using a JAR file
- Longer download times.
- Extra work to retrieve sources.
META-INF/
MANIFEST.MF
com/
CodingNinja/
MyApplication.class
EAR
EAR stands for Enterprise Archive. This file represents the enterprise application. The WAR and JAR files are packaged as a JAR file with .ear extension. The EAR file deploys modules into the Application server.
It plays a crucial role in deploying service to a production server. It can contain multiple Web modules and EJB modules. As in the META-INF folder, it includes an application.xml file, and because of this, it is known as a special JAR.
Advantages of using an EAR file
- Can aggregate several, unlike applications.
- The file size can be reduced.
- Restoring links is not necessary.
- Comparatively easier to deploy than the above two.
Disadvantages of using EAR file
- Requires a java platform completely.
<?XML version="1.0"?> <jboss-app> <loader-repository> loader=nameofyourear.ear <loader-repository-config>java2ParentDelegation=false</loader-repository-config> </loader-repository> </jboss-app>