The difference between jar package and war

1. War is a web module, which must include WEB-INF, which is a web project that can be run directly.

      The jar generally only includes some class files, which can be run with the java command after declaring Main_class.

2. The javaSE program can be packaged into a jar package (J can be understood as java). The javaWeb program can be packaged into a war package (W can be understood as web), and then publish the war to the directory under the webapps of tomcat, and tomcat will automatically decompress the war package when it starts.

3. jar (JavaArchive, Java Archive) is a platform-independent file format that allows many files to be combined into a single compressed file. The jar files created for J2EE applications are ear files (enterprise jar files).

4. A WAR file is a web application. To create a WAR file is to create an entire web program (excluding the root directory of the web application hierarchy) and compress it, specifying a .war extension.

5. The file format of war file and jar file is the same, and both are created using the jar command, but in terms of their application, war file and jar file are fundamentally different. The purpose of a jar file is to encapsulate classes and related resources into a compressed archive, while for a war file, a war file represents a web application, which can contain servlets, html pages, java classes, image files, and Other resources that make up a web application, not just an archive.

6. Jar files (extension .Jar Jave Application Archive) include common Java classes, resources, auxiliary files, etc.;

The war file ( extension .War, Web Application Archive ) contains all Web applications. In this case, a Web application is defined as a single set of files, classes, and resources, and the user can encapsulate the jar file and access it as a small service program (servlet).

The ear file (extension .Ear, Enterprise Application Archive) contains all enterprise applications. In this case, an enterprise application is defined as a collection of jar files, resources, classes, and web applications.

  Each type of file (.jar, .war, .ear) can only be processed by application servers, servlet containers, EJB containers, etc.

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 decompress the web1.war file directly, you can use the command: jar -xvf web1.war

In addition, you can also use winrar software to select the zip compression method, and change the suffix name of the compressed file to war to compress and generate a war file; also use winrar software to forcibly open the war file, or forcibly decompress the war file

The difference between using the jar command and the winrar software is that the former will generate a MetaINF folder while compressing the file, which contains the MANIFEST.MF file.

 

Summarize:

         When to use war or jar files: When your project is not fully completed, it is not suitable to use war files, because your classes will be changed frequently due to debugging and so on, so it is very uncomfortable to delete and create war files back and forth, it is best It is your project that has been completed and will not be changed, then make a war package . At this time, a war file is equivalent to a web application bird; and a jar file is to encapsulate classes and some related resources into a package. , for easy reference in the program.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324645285&siteId=291194637