WAR and EAR file format

本文介绍了WAR(Web Application Archive)和EAR(Enterprise Archive)文件格式。WAR文件是一种用于打包Java Web应用程序的标准格式,包含了JSP页面、Servlets、类文件等资源。而EAR文件则进一步将多个模块整合为一个单元进行部署。文章详细解释了WAR文件中关键的web.xml配置文件的作用,并概述了EAR文件的用途。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

看Jenkins的时候,安装运行Jenkins时用的是WAR包,所以我就看看什么是war包。

http://en.wikipedia.org/wiki/WAR_file_format_%28Sun%29


In computing, a WAR file (or Web applicationARchive) is aJAR file used to distribute a collection of JavaServer Pages, Java Servlets, Javaclasses, XML files, tag libraries and static Web pages (HTML and related files) that togetherconstitute a Web application.


所以Jenkins使用war非常合理,因为Jenkins是一个Web application。而There are special files and directories within a WAR file.


The /WEB-INF directory in the WAR file contains a file named web.xml which defines the structure of the web application. If the web application is only serving JSP files, the web.xml file is not strictly necessary. If the web application uses servlets, then the servlet container uses web.xml to ascertain to which servlet a URL request is to be routed. web.xml is also used to define context variables which can be referenced within the servlets and it is used to define environmental dependencies which the deployer is expected to set up. An example of this is a dependency on a mail session used to send email. The servlet container is responsible for providing this service.

因此web.xml非常重要,下面是例子:

 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE web-app
     PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
     "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
 
 <web-app>
     <servlet>
         <servlet-name>HelloServlet</servlet-name>
         <servlet-class>mypackage.HelloServlet</servlet-class>
     </servlet>
 
     <servlet-mapping>
         <servlet-name>HelloServlet</servlet-name>
         <url-pattern>/HelloServlet</url-pattern>
     </servlet-mapping>
 <!--上面就是前面说的:the servlet container uses web.xml to ascertain to which servlet a URL request is to be routed

当用户在URL输入.../HelloServlet时,就知道请求的是servlet HelloServlet,同时背后应执行的java类是mypackage.HelloServlet-->
     <resource-ref>
         <description>
             Resource reference to a factory for javax.mail.Session
             instances that may be used for sending electronic mail messages,
             preconfigured to connect to the appropriate SMTP server.
         </description>
         <res-ref-name>mail/Session</res-ref-name>
         <res-type>javax.mail.Session</res-type>
         <res-auth>Container</res-auth>
     </resource-ref>
 </web-app>

The /WEB-INF/classes directory is on the ClassLoader's classpath. This is where .class files are loaded from when the web application is executing. Any JAR files placed in the /WEB-INF/lib directory will also be placed on the ClassLoader's classpath.

Advantages of WAR files:

  • security - no one can modify the deployment, once the war file is signed and deployed
  • easy development, testing and deployment
  • the version of the deployed application is easily identified
  • all J2EE containers support .WAR files

One disadvantage of web deployment using WAR files in very dynamic environments is that minor changes cannot be made during runtime. Any change whatsoever requires regenerating and redeploying the entire WAR file.


总之这个wiki写的很精华,值得一看。


再来看看EAR

http://en.wikipedia.org/wiki/EAR_%28file_format%29

EAR (Enterprise Archive) is a file format used by Java EE for packaging one or more modules into a single archive so that the deployment of the various modules onto an application server happens simultaneously and coherently. It also contains XML files called deployment descriptors which describe how to deploy the modules.

Ant or Maven can be used to build EAR files.

An EAR file is a standard JAR file (and therefore a Zip file) with a .ear extension, with one or more entries representing the modules of the application, and a metadata directory called META-INF which contains one or more deployment descriptors.



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值