From a customer perspective, a jar file is an encapsulation format that users do not need to know how many. class files in the jar package and the functions and roles in each file can also be obtained by corresponding access results. In addition to the jar format, Java has package files such as war and ear.
|
Jar |
WAR |
EAR |
English |
Java Archive File |
Web Archive File |
Enterprise Archive File |
Include content |
Class, properties file, is the smallest unit of file encapsulation, including Java Class Common library, resources, auxiliary files (auxiliary files), etc. |
Servlets, JSP pages, JSP tag libraries, jar library files, html/xml documents, and other common resource files, slices, audio files, etc. |
In addition to including jars and wars, EJB components are included |
Deployment files |
Application-client.xml |
Xml |
Application.xml |
Container |
Application Server (application servers) |
Small Service Program container (servlet containers) |
EJB container (EJB containers) |
Level |
Small |
In |
Big |
1. EAR Packaging of files
The ear file includes the entire JSP project, which contains multiple EJB module (jar files) and Web Module (war files).
The ear file generation can be generated using WinRAR (software on the Windows platform) in zip compression or from the command line as a jar command.
The internal structure of the typical ear package is as follows:
App.ear
| Ejb.jar//Ejb-jar bag
| Other.jar//Common jar Package
| Webapp.war//War pack
|
|-meta-inf
Application.xml//Ear profile
Common cases:
Create an ear project + Create a war project and put the ear in the ear = deploy the ears to was
Operation Steps:
1) first package into war and jar, and write good application.xml, put in Meta-inf directory.
2) Packaging command: (enter the directory where the file is located)
Jar CF application.ear Application.war application.jar meta-inf\application.xml
Note: Application.xml is used to describe package files such as war and Jar included in the ear
3) Unpack the command:
Jar XF application.ear-c target path
Examples of the application.xml of WebLogic Petstore:
<! DOCTYPE application Public '-//sun Microsystems, INC.//DTD Java EE 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</cont ext-root> </web> </module> <module> <ejb>petstoreejb.jar</ejb> ; </module> <module> <ejb>signonEjb.jar</ejb> </module> <module> <ejb>personalizationEjb.jar</ejb> </module> <module> <ejb>inven toryejb.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 cu Stomer role</description> <role-name>customer</role-name> </security-role> < security-role> <role-name>administrator</role-name> </security-role> </application& Gt
2. WAR the Use
1) Generate War Package file command:
JAR-CVF Web.war Packaged Files
Or: With the Eclipse tool, click on the project, right-click, select "Export", select "WAR" format in the popup dialog, select the path, and export the resulting WAR file directly in Tomcat's WebApps directory to start Tomcat, It will be automatically decompressed and can be accessed when the boot is complete.
2) View the War Package Contents command:
JAR-TF Web.war
3) Unzip the war package file command:
JAR-XF Web.war
You can also use the WinRAR software to select Zip compression, and then change the compressed file suffix name to war to compress the resulting war file. You can also use the WinRAR software to open the war file, or unzip the war file.
The difference between using the jar command and the WinRAR software is that the Meta-inf folder, which contains the MANIFEST.MF file, is generated while the file is compressed.
3. when to use a war or jar file
When a project is not fully developed, it is not appropriate to use the war file, because your class will be cumbersome to create a war package back and forth because it is often modified by debugging. You can create a war package when the project is fully developed and you do not need to modify it later. This time the war package file is equivalent to a Web application, and the jar file encapsulates the class and some related resources into a package for easy reference in the program.
The internal structure of a typical war package is as follows:
Webapp.war
| index.jsp
|
|-images
|-meta-inf
|-web-inf
| Web. XML//War package description file
|
|-classes
| Action.class//Java class file
|
|-lib
Other.jar//Dependent jar Package
Share.jar
The internal structure of the typical jar package is as follows:
Tools.jar
| Resource.xml//Resource configuration file
| Other.xml
|
|-meta-inf
| MANIFEST. MF//Jar Package description file
|-com//Class of package directory
|-test
Util.class//java class file
4, the role of Jar/war/ear package file and the difference:
4.1 , function and Difference
1) Jar: the development to refer to generic (JAVA) classes and resources to do encapsulation, after the package to facilitate storage management;
2) War: A (web) complete application, usually a Web site or web platform, to be deployed into a container;
3) Ear: Enterprise applications, in fact, the ear package contains a war package and several enterprise-level project configuration files, server middleware typically choose WebSphere, etc. will use the ear package. Typically, an EJB is called into an ear packet.
4.2 , Packaging methods
1) All packages are made with the jar command, except that the target file has a different extension.
2) can also be built with Ant.
3) Windows platform WinRAR command.
4.3 , Jet compiled into EXE
1) Jet is money to buy, it is said that jet is not able to all Java programs are compiled to execute files, performance also have some discount. So, the best way to make the executable JAR file package is to keep the Java cross-platform feature.
The role and difference of jar/war/ear and other packages