Java based packaging jar war ear package role and differences
- 2020-04-01 01:44:22
- OfStack
From the end customer's point of view, JAR files are a form of encapsulation, and they don't need to know how many. Class files are in the JAR file, and the functions and roles in each file can still get the results they want. In addition to the jar, there are wars and ears for J2EE. The differences are shown in the following table:
The JAR
The WAR
The EAR
English
Java Archive file
Web Archive file
Enterprise Archive file
Contains the content
The class, properties file is the smallest unit of file encapsulation. Contains common libraries of Java classes, resources, auxiliary files, etc
Servlets, JSP pages, JSP tag libraries, JAR library files, HTML/XML documents, and other common resource files, such as images, audio files, and so on
In addition to containing jars and wars, EJB components are included
Deployment file
Application - client. XML
web.xml
XML application.
The container
Application servers
Small server container (servlet containers)
EJB containers
level
small
In the
big
(1) packaging of the EAR file
The EAR file includes the entire project and contains multiple EJB modules (JAR files) and Web modules (WAR files).
The generation of the EAR file can be zip compressed using winrar or as a jar command from the command line.
Steps:
1 > Package it as war and jar, write application.xml, and place it in META - INF Directory.
2 > , run jar cf your_application.ear your_war.war your_jar.jar meta-inf \application.xml (assuming both are in the current directory).
Of course, you can also unzip it with jar xf your_application.ear.
Application.xml is used to describe the war and jar included in your ear
Example of application.xml from petstore that comes with weblogic:
<!DOCTYPE application PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN' 'http://java.sun.com/j2ee/dtds/application_1_2.dtd'>
<application>
<display-name>estore</display-name>
<description>Application description</description>
<module>
<ejb>customerEjb.jar</ejb>
</module>
<module>
<ejb>mailerEjb.jar</ejb>
</module>
<module>
<web>
<web-uri>petstore.war</web-uri>
<context-root>estore</context-root>
</web>
</module>
<module>
<ejb>petstoreEjb.jar</ejb>
</module>
<module>
<ejb>signonEjb.jar</ejb>
</module>
<module>
<ejb>personalizationEjb.jar</ejb>
</module>
<module>
<ejb>inventoryEjb.jar</ejb>
</module>
<module>
<ejb>shoppingcartEjb.jar</ejb>
</module>
<security-role>
<description>the gold customer role</description>
<role-name>gold_customer</role-name>
</security-role>
<security-role>
<description>the customer role</description>
<role-name>customer</role-name>
</security-role>
<security-role>
<role-name>administrator</role-name>
</security-role>
</application>
(2) the use of the WAR
1 > To generate the war file, use the following command: jar - CVF Web1. War *
2 > To see what's in web1.war, use the command jar - tf Web1. War
3 > To unzip the web1.war file, you can use the command jar - XVF Web1. War
In addition, you can also use winrar software to choose zip compression, and the compressed file suffix name changed to war can be compressed to generate war file; The same winrar software can be used to force open a war file, or forced to unzip a war file
The difference between using the jar command and winrar software is that the former generates meta-inf while compressing the file; Folder containing the manifest.mf file.
(3) when to use a war or jar file
When your project are not fully completed, is not suitable for using the war file, because your class will often change due to debug, and delete, create the war file is very bad, had better be your project has been completed, is not changed, then make a war file, this time a war file is equivalent to a web application; Jar files, on the other hand, encapsulate classes and related resources into a package that is easy to refer to in a program.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Java packaging jar, war, ear package role, difference, packaging:
1. Functions and differences
I. Jar: usually refers to generic (JAVA) classes at development time and is packaged for easy storage and management.
Ii.war: is when a (web) application, usually a web site, is packaged and deployed into a container;
Iii. Ear: enterprise application. In fact, the ear package contains only the WAR package and configuration files of several enterprise projects. Typically, ejbs go into an ear package.
2. Packing method
I. All the packages are in jars, but the extension of the target file is different.
Ii. Can also be built with Ant.
3, JET compiled to EXE
I. JET is a money purchase, and it is said that JET does not compile all Java programs into executable files, and its performance is somewhat compromised. Therefore, using the method of producing executable JAR file packages is the best choice, and it preserves the cross-platform nature of Java.
Note:
After exporting the web project in the form of war, directly put it under the tomcat container webapps, start the service, and you can run the project. The war package will automatically unzip a folder with the same name.