问题描述
- war和ear有什么区别?分别在什么情况下使用?
-
J2EE应用能打包成war文件和ear文件。这两个文件有什么区别?什么时候用war?什么时候用ear?
解决方案
jar/war /ear三种文件,在文件结构上,三者并没有什么不同,它们都采用zip或jar档案文件压缩格式。但是它们的使用目的有所区别:
Jar文件(扩展名为. Jar)包含Java类的普通库、资源(resources)、辅助文件 (auxiliary files)等
War文件(扩展名为.War)包含全部Web应用程序。在这种情形下,一个Web应用程序被定义为单独的 一组文件、类和资源,用户可以对jar文件进行封装,并把它作为小型服务程序(servlet)来访问。
Ear文件(扩展名为.Ear)包含全部企业应用程序。在这种情形下,一个企业应用程序被定义为多个jar 文件、资源、类和Web应用程序的集合。
每一种文件(.jar, .war, .ear)只能分别由应用服务器(application servers)、小型服务程序容器(servlet containers)、EJB容器(EJB containers)等进行处理。
解决方案二:
jar(Java Archive file );
war( Web Archive file);
ear(Enterprise Archive file )
jar:包含内容 class、properties文件,是文件封装的最小单元;
war:Servlet、JSP页面、JSP标记库、JAR库文件、HTML/XML文档和其他公用资源文件,如图片、音频文件等;
ear:除了包含 JAR、WAR以外,还包括EJB组件
部署文件 application-client.xml web.xml application.xml
级别 小 中 大
jar:封装类 war:封装web站点 ear:可以封装ejb
JAR: Software developers generally use .jar files to distribute Java applications or libraries, in the form. of classes and associated metadata and resources (text, images, etc.) JAR files build on the ZIP file format.
WAR: In computing, a WAR file (which stands for "web application archive" ) is a JAR file used to distribute a collection of JavaServer Pages, servlets, Java classes, XML files, tag libraries and static Web pages (HTML and related files) that together constitute a Web application.
EAR: An Enterprise ARchive, or EAR, 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. Maven or Ant can be used to build EAR files.
RAR: A Resource Adapter is an archive file format defined in the J2EE Connector Architecture (JCA) specification. A Resource Adapter aRchive (RAR) file is the valid format for deployment of resource adapters on application servers. J2EE RAR files may also be called connectors.