Java-based packaging jar, war, ear packet function and difference detailed _java

Source: Internet
Author: User
Tags xml example zip

In the end customer's perspective, the jar file is an encapsulation, and they don't need to know how many. class files in the jar file, the functions and roles in each file, can also get the results they want. Besides jars, there are war and ear for the Java EE. The difference is shown in the following table:

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; A common library, resource (resources), auxiliary files (auxiliary files) containing Java classes, etc. Servlet, JSP page, JSP Tag library, jar library file, Html/xml document, and other common resource files such as pictures, audio files, etc. In addition to containing jars, war, 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 ear files

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

The generation of ear files can be generated using WinRAR in zip compression or from the command line with JAR commands.

Steps:

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

2>, run 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 Jar XF your_application.ear to extract.

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

The application.xml example of WebLogic's Petstore :

Copy Code code 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 war files use 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>, extract Web1.war files, you can use the command : JAR-XVF Web1.war

In addition, you can use the WinRAR software to select Zip compression, and the compressed file suffix to war can be compressed to generate 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 former generates a Meta-inf folder, containing MANIFEST, while compressing the file . MF file.

(3) When to use war or jar files

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

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

Java packaging jar, war, the role of the ear package, differences, packaging methods:

1. Function and Difference

I. jar: Usually the development time to refer to the common (JAVA) class, to make a package easy to store management;

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

Iii. Ear: Enterprise-class applications, in fact, the ear package contains a war package and several enterprise-level project configuration files, the general server chooses WebSphere, and so on, will use the ear package. EJB is usually the ear packet.

2. Packing method

I. All packages are typed with jars, except that the target file extension is not the same;

II. You can also use ant to Ancheng constructs.

3, Jet compiled into EXE

I jet is to be bought with money, and it is said that jet is not able to compile all Java programs into execution files, and performance discounts. So, the way to make an executable JAR package is the best choice, not to mention the ability to maintain the cross-platform nature of Java.

Attention:

When the Web project is exported as a war, it is placed directly under the WebApps of the Tomcat container , starts the service, and runs the project, which automatically extracts a folder with the same name.

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.