recently contacted these words more, stopped to summarize their differences and connections, a better understanding
Jar, war, EAR, file structure, the three are not different, they are in the zip or jar file compression format . But the purpose of their use is different:
jar file with the extension. Jar,java application Archive) contains generic libraries for Java classes, resources, auxiliary files (auxiliary files), etc.
War file (with the extension. War,web application Archive) contains all WEB applications. In this case, a Web application is defined as a separate set of files, classes, and resources, and the user can encapsulate the jar file and access it as a small service program (servlet).
Ear File (with the extension. Ear,enterprise application Archive) contains all enterprise applications. In this case, an enterprise application is defined as a collection of multiple jar files, resources, classes, and Web applications.
Each file (. jar,. War,. Ear) can be processed only by the application server (application servers), the Small service container (servlet containers), the EJB container (EJB containers), and so on.
The ear file includes the entire project, with multiple EJB module (jar files) and Web module (war file)
The ear file can be generated using WinRAR zip compression or jar commands.
Steps:
Pack the war and Jar first, write the Application.xml, put it in the Meta-inf directory, and then the jar CF your_application. ear Your_war.war Your_jar.jar meta-inf/application.xml, packaged, I assume that all in the current directory can be used with the jar XF Your_applica tion. Ear Decompression
Application.xml describes the war and jar included in your ear (as mentioned in the previous article)
Examples of application.xml in JBoss
<span style= "FONT-SIZE:18PX;" ><span style= "FONT-SIZE:18PX;" ><?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE application Public "-//sun Microsystems, inc.//dtd EE application 1.3//en" "http://java.sun.com/dtd/ Application_1_3.dtd "><application> <display-name>lishehetestear</display-name> <module> <java>lishehe_api-0.0.1-SNAPSHOT.jar</java> </module> <module > <java>lishehe_core-0.0.1-SNAPSHOT.jar</java> </module> <module> <web> <web-uri>lishehe_war-0.0.1-SNAPSHOT.war</web-uri> <context-root>/ lishehe_war</context-root> </web> </module></application></span></ Span>
Use of War:
If you want to generate a war file: You can use the following command: JAR-CVF Web1.war *
If you want to see what files are in Web1.war, you can use the command: JAR-TF Web1.war
If you want to extract the Web1.war file directly, 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 Metainf folder, which contains the MANIFEST.MF file, is generated while the file is compressed.
Summarize:
When to use a war or jar file: 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 bag it , this time a war file is equivalent to a Web application bird, while a jar file encapsulates a class and some related resources into a package for easy reference in the program.
Use and difference of JAR, WAR, ear