请教熟悉Weblogic6。1的类加载结构的高手!

Section 8.1.1.2 of the J2EE 1.3 specification mandates explicit support for the bundling of dependent .jar files via the Extension Mechanism Architecture (see the References section). Application servers must load dependent .jar files listed in the Manifest Class-Path entry of a primary .jar file (typically an EJB .jar). This requirement is not mandated for .ear or .war files.

As of Service Pack 2 of WebLogic 6.1 (WebLogic issue 056911 -- see the References section below), .jar files listed in a Manifest Class-Path entry are loaded by the application's EJB class loader. This applies to Manifest Class-Path entries found in EJB .jar files and web application .war files within the .ear. Note that the Manifest Class-Path approach is only supported when deploying components within an .ear.


我测试用的目录结构是这样的:application目录下有一些ejb .jar文件,有一个certificate.war,soap.war,还有一个DefaultWebapp目录。我写了一个StatefulAccount ejb,打包StatefulAccount.jar,它用到的帮助类打包成helper.jar,这两个jar文件都在application目录下。在StatefulAccount.jar的清单文件中,加入了Class-Path: helper.jar。部署ejb的时候没有问题,就是在运行的时候抛出ClassDefNotFound异常。这个异常说明找到了类文件,应该是类文件的格式不对。

为什么会这样呢?

jbuilder生成的jar包中的清单文件:
Manifest-Version: 1.0

Name: META-INF/ejb-jar.xml

Name: bank/StatefulAccountBean.class

Name: bank/StatefulAccountHome.class

Name: META-INF/weblogic-ejb-jar.xml

Name: bank/StatefulAccount.class

我只是在最后加了一行:
Manifest-Version: 1.0

Name: META-INF/ejb-jar.xml

Name: bank/StatefulAccountBean.class

Name: bank/StatefulAccountHome.class

Name: META-INF/weblogic-ejb-jar.xml

Name: bank/StatefulAccount.class

Class-Path: helper.jar

部署的时候就报错说清单文件的格式不正确,后来我把所有的Name都删掉,变成这样:
Manifest-Version: 1.0

Class-Path: helper.jar

部署就能通过,可是访问ejb的时候又抛出ClassDefNotFound而不是ClassNotFoundException,真是太奇怪了。

我们公司把所有的ejb放在applications目录下,web模块就用现成的DefaultWebApp目录。导致一些公用类必须在ejb 。jar包中有一份,在web模块中还要有一份(这一份本来是不必要的)。
这样做肯定是不对的,但是我不知道正确的做法是怎么样的。

你是在什么里面调用ejb的?是在DefaultWebapp中调用吗?如果是这样的话,肯定找不到ejb的类。

因为DefaultWebapp的classloader不是StatefulAccount.jar的孩子。

weblogic的classloader的层次:

-- system classpath classloader
+-- ejb1 classloaer
+-- webapp classloader
+-- ejb2 classloader
+-- webapp2 classloader

在webapp中加载一个类,首先委托他的父ejb classloader.

所以DefaultWebApp的classloader 是不能够委托你的那个ejb的classloader的。所以是找不到ejb的类。