I have a few separate application projects (EARs) with multiple EJBs that I want to deploy to the same JBoss server. Now, some of the projects may have the same EJBs, but different versions. In similar circumstances, some projects may use different versions of the same "ordinary" classes (i.e. classes loaded within VM, without JNDI lookup).
我有几个单独的应用程序项目(EAR),包含多个EJB,我想将它们部署到同一个JBoss服务器上。现在,一些项目可能具有相同的EJB,但版本不同。在类似的情况下,一些项目可能使用相同“普通”类的不同版本(即在VM中加载的类,没有JNDI查找)。
With OC4J, this seems not to have been a problem, but now with JBoss, I get the impression that everything resides in the same "name space" (or class loader perhaps). Am I correct in this assumption?
使用OC4J,这似乎不是一个问题,但现在使用JBoss,我得到的印象是所有内容都存在于相同的“名称空间”(或类加载器)中。我在这个假设中是否正确?
Basically, what I want to do (or ensure) are two things:
基本上,我想做(或确保)的是两件事:
-
From a client that does a JNDI-lookup of an EJB, I want to be able to indicate which application it resides in, so that the correct version of the EJB is returned.
从执行EJB的JNDI查找的客户端,我希望能够指示它所在的应用程序,以便返回正确的EJB版本。
-
From within an EJB, when instantiating a class, I want to ensure that the class is the one deployed with the same application (EAR) as the EJB was.
在EJB中,在实例化类时,我想确保该类是使用与EJB相同的应用程序(EAR)部署的类。
I think I read that you could configure some "isolation" properties for EJBs, am I guessing correctly in that might would solve my second point?
我想我读过你可以为EJB配置一些“隔离”属性,我猜错了可能会解决我的第二点吗?
2 个解决方案
#1
You're correct that classes from different EAR's reside in the same "space". JBoss uses by default a flat classloader hierarchy, meaning that all classes (except for WAR packaged ones) are loaded by the same classloader. With the introduction of JBoss 5 there's a new standard profile that strictly follows the Java EE rules and thus supports isolated classloading. Older JBoss versions also support this behavior through the callByValue and isolate properties in the deployer configuraion.
你是对的,来自不同EAR的类存在于同一个“空间”中。 JBoss默认使用平面类加载器层次结构,这意味着所有类(WAR打包的类除外)都由同一个类加载器加载。随着JBoss 5的推出,有一个新的标准配置文件严格遵循Java EE规则,因此支持隔离的类加载。较旧的JBoss版本也通过callByValue支持此行为,并在部署程序配置中隔离属性。
#2
JBoss's default behaviour is to use a flat classloader. This reduces the footprint, but as you've found, it makes deploying multiple applications troublesome.
JBoss的默认行为是使用平面类加载器。这样可以减少占用空间,但正如您所发现的那样,它会使部署多个应用程序变得麻烦。
Thankfully, the fix is easy. In the ear-deployer.xml
file in the deploy
directory, make sure the following parameter is set:
谢天谢地,修复很简单。在deploy目录的ear-deployer.xml文件中,确保设置了以下参数:
<attribute name="Isolated">true</attribute>
This will give each deployed EAR its own classloader space. It will still be able to access stuff from the JBoss lib directory, but the deployed EARs will be invisible to each other.
这将为每个部署的EAR提供自己的类加载器空间。它仍然可以从JBoss lib目录访问东西,但是部署的EAR彼此是不可见的。
#1
You're correct that classes from different EAR's reside in the same "space". JBoss uses by default a flat classloader hierarchy, meaning that all classes (except for WAR packaged ones) are loaded by the same classloader. With the introduction of JBoss 5 there's a new standard profile that strictly follows the Java EE rules and thus supports isolated classloading. Older JBoss versions also support this behavior through the callByValue and isolate properties in the deployer configuraion.
你是对的,来自不同EAR的类存在于同一个“空间”中。 JBoss默认使用平面类加载器层次结构,这意味着所有类(WAR打包的类除外)都由同一个类加载器加载。随着JBoss 5的推出,有一个新的标准配置文件严格遵循Java EE规则,因此支持隔离的类加载。较旧的JBoss版本也通过callByValue支持此行为,并在部署程序配置中隔离属性。
#2
JBoss's default behaviour is to use a flat classloader. This reduces the footprint, but as you've found, it makes deploying multiple applications troublesome.
JBoss的默认行为是使用平面类加载器。这样可以减少占用空间,但正如您所发现的那样,它会使部署多个应用程序变得麻烦。
Thankfully, the fix is easy. In the ear-deployer.xml
file in the deploy
directory, make sure the following parameter is set:
谢天谢地,修复很简单。在deploy目录的ear-deployer.xml文件中,确保设置了以下参数:
<attribute name="Isolated">true</attribute>
This will give each deployed EAR its own classloader space. It will still be able to access stuff from the JBoss lib directory, but the deployed EARs will be invisible to each other.
这将为每个部署的EAR提供自己的类加载器空间。它仍然可以从JBoss lib目录访问东西,但是部署的EAR彼此是不可见的。