Java War package, war package and jar package differences

Source: Internet
Author: User

From an end-customer perspective, a jar file is an encapsulation, and they don't need to know how many. class files are in the jar file, and the function and function of each file also gives them the desired result. In addition to the jar, there are war and ear ears for the Java EE. The difference is shown in the following table:

java Archive file TD width= "335" >
Jar WAR EAR
English web Archive file < Span style= "Font-family:microsoft Yahei; font-size:15px ">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) Packaging of the ear file

The ear file includes the entire project and contains multiple EJB module (jar files) and Web Module (war files).

The generation of the ear file can be generated using WinRAR as a zip compression or as a jar command from the command line.

Steps:

1>, first package into war and jar, and write good application.xml, put in Meta-inf directory.

2>, run the jar CF your_application.ear Your_war.war Your_jar.jar meta-inf\application.xml (assuming all in the current directory).

Of course, you can also use the Jar XF your_application.ear to decompress.

Application.xml is used to describe the war and jar included in your ear.

Examples of the application.xml of WebLogic Petstore :

Copy CodeThe code is as follows:
<! 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</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) Use of War

1>, generate the war file using the following command:JAR-CVF Web1.war *
2>, see what files are in Web1.war, you can use the command:JAR-TF Web1.war
3>, unzip the Web1.war file, you can use the command : JAR-XVF Web1.war

In addition, you can use the WinRAR software to select the Zip compression method, and the compressed file suffix to the war can be compressed to generate a war file, also use the WinRAR software can forcibly open the war file, or forcibly extract the war file

The difference between using the jar command and the winrar software is that the Meta-inf folder, which contains MANIFEST, is generated while the file is compressed . MF file.

(3) When to use war or jar files

When your project is not fully completed, it is not appropriate to use the war file, because your class will often change because of debugging, such as to delete, create a war file is very uncomfortable, preferably your project has been completed, do not change, then make a war package it, At this point a war file is equivalent to a Web application, and a jar file encapsulates a class and some related resources into a package for easy reference in the program.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

The role, difference, and packaging of Java's packaged jar, war, ear package:

1. Function and Difference

I. jar: Usually the development time to refer to the generic (JAVA) class, into a package for easy storage management;

II. War: is to do a (web) application, usually a Web site, into a package deployed into the container;

Iii. Ear: Enterprise applications, in fact, the ear package contains a war package and several enterprise-level project configuration files, the general server select WebSphere, etc., will use the ear package. Typically, an EJB is called into an ear packet.

2. Packing method

I. All packages are hit with jars, except that the target file has a different extension;

II. You can also use ant to build Ancheng.

3, Jet compiled into EXE

I. Jet is money to buy, and it is said that jet is not able to compile all the Java programs to execute files, performance also have to discount. So, the best way to make the executable JAR file package is to keep the Java cross-platform feature.

Attention:

After the Web project is exported as a war, it is placed directly under the WebApps of the Tomcat container and the service is started, and the War package automatically extracts a folder with the same name.

Java War package, war package and jar package differences

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.