1、打包文件命名規則
根據JavaEE規范,打包的EAR文件可以不適用部署描述符部署,因此需要使用一些默認的約定規則,例如
•EJBs and client archives are packaged as .jar files.
•Web applications are packaged as .war files.
•Resource adapters are packaged as .rar files.
•Enterprise applications are packaged as .ear files, and can contain other Java EE modules such as EJBs, JDBC, JMS, Web applications, and Resource Adapters.
•Web Services can be packaged either as .war files or as .jar files, depending on whether they are implemented using Java classes or EJBs. Typically, the .war or .jar files are then packaged in an Enterprise Application .ear file.
•Java EE libraries are packaged either as an Enterprise Application (.ear file) or as a standard Java EE module.
•Client applications and optional packages are packaged as .jar files.
2、Java EE默認部署規則
通常EAR應用也可以使用開放式目錄部署,此時也應該參考以上的規范配置相應的文件夾,例如
war應用目錄名必須為XX.war
EAR==>xx.ear
RAR==>XX.rar
EJB==>xx.jar
3、Java EE標準的部署規則
a. 應用包中所有擴展名是.war 的文件被看作是 web 模塊。Web 模塊的上下文根
的名字是相對于應用包根的名字,但要去掉.war 擴展名。
b. 應用包中所有擴展名是.rar 的文件都被看作是資源適配器。
c. 名字為 lib 的目錄被看作是庫目錄,正如在節 8.2.1“捆綁的庫”中所述。
d. 對于應用包中所有以擴展名是.jar 但不包含在 lib 目錄內的文件來說,按下面 的方式來處理:
i. 如果 JAR 文件中包含帶有 Main‐Class 屬性的 META‐INF/MANINFEST.MF 文件, 或者包含 META‐INF/application‐client.xml 文件,那么這個 JAR 文件被看作 是應用客戶端模塊。
ii. 如果 JAR 文件包含 META‐INF/ejb‐jar.xml 文件,或者包含任何帶有 EJB 組件 注釋符(Stateless,等等)的類,那么這個 JAR 文件被看作是 EJB 模塊。
iii. 所有其他的 JAR 文件都被忽略,除非它被上面的 JAR 文件使用 JAR 文件引 用機制(如在 mainfest 文件中的 Class‐Path 頭library-directory)引用。
在Jboss環境中,可以在application.xml中手工指定library-directory,例如:
<library-directory>APP-INF/lib</library-directory>
其他的jboss遵循標準規范
4、Weblogic的部署規則
對于weblogic使用下面的一些規則處理目錄結構:
•For an exploded archived Web application, in the absence of WEB-INF/web.xml descriptor, the name of the directory should have a .war suffix.
•For an exploded archived Enterprise Application without a META-INF/application.xml descriptor, the directory should have an .ear suffix. Within the application, the directory of exploded Web module should have a .war suffix. Similarly, the exploded EJB module should have a .jar suffix and the exploded RAR module should have a .rar suffix.
•If an exploded Enterprise Application contains no META-INF/application.xml descriptor, the order in which modules are deployed is undefined and is dependent on the underlying File.listFiles() method order. To ensure a specific order in which modules are deployed, you must add an application.xml descriptor and list the modules in the desired order.
如果在weblogic下面如果不使用上面的規則,則需要在application.xml 文件中指定對應的uri路徑
或者在應用模塊中使用下面的manifest路徑規則
4.1 classloader的路徑引用
在weblogic中EAR里面的所有應用共有一個classloader,所以對于ear里面的war,通常不需要在WEB-INF里面包含lib,weblogic提供了一個默認的目錄:
APP-INF\lib:存放jar包
APP-INF\classes:存放classes
注意對于其他的應用服務器,可能沒有這樣的規則
5、Manifest Class-Path規則
在java EE規范中,可以使用manifest文件指定當前的應用模塊對與其他classpath路徑的關聯引用,該文件位于
META-INF/MANIFEST.MF
路徑下面,內容例如下面,多個引用路徑使用空格分隔:
Manifest-Version: 1.0
Class-Path: utility.jar ../xxx/classes ../xxxlib/xxx.jar
META-INF/MANIFEST.MF
Manifest Class-Path
參考頁面:
http://docs.oracle.com/cd/E12839_01/web.1111/e13706/classloading.htm
http://docs.oracle.com/cd/E12839_01/web.1111/e13702/deployunits.htm#DEPGD142