.jar/war/ear包的區別

來源:互聯網
上載者:User

以最終客戶的角度來看,.jar檔案就是一種封裝,他們不需要知道.jar檔案中有多少個.class檔案,每個檔案中的功能與作用,同樣可以得到他們希望的結果。除jar以外對於J2EE來說還有war和ear。區別見下表:

 

 JAR

 WAR

 EAR

 英文  Java Archive file   Web Archive file  Enterprise Archive file
 包含內容  class、properties檔案,是檔案封裝的最小單元;  Servlet、JSP頁面、JSP標記庫、JAR庫檔案、HTML/XML文檔和其他公用資源檔,如圖片、音頻檔案等;  除了包含JAR、WAR以外,還包括EJB組件
 部署檔案  application-client.xml   web.xml     application.xml
 層級   小  中  大

 

 

經常在我們Java Web項目中看到jar/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 WAR EAR  
  英文 Java   Archive   file ; Web   Archive   file 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.

其他概念:
EJB: Enterprise JavaBeans (EJB) is a managed, server-side component architecture for modular construction of enterprise applications. The EJB specification is one of several Java APIs in the Java EE. EJB is a server-side model that encapsulates the business logic of an application.
JavaBean: JavaBeans are reusable software components for Java that can be manipulated visually in a builder tool. Practically, they are classes written in the Java programming language conforming to a particular convention. They are used to encapsulate many objects into a single object (the bean), so that they can be passed around as a single bean object instead of as multiple individual objects. A JavaBean is a Java Object that is serializable, has a nullary constructor, and allows access to properties using getter and setter methods.
Metadata: Metadata is a means to describe the data files.It provides information about a certain item's content, such as: means of creation, purpose of the data, time and date of creation, creator or author of data, placement on a network (electronic form) where the data was created, what standards used (ISO9000), etc.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.