• Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB access and classloader

 
Yuan Ye
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an impression that in Tomcat, each war file is deployed by its own classloader, so a class in one war file can't see the class in another war file, is this correct?
I am assuming the same architecture with JBoss server, at runtime one class can not see another class if they belong to two different .ejb3 files. However after some tests, seems Jboss is using a single classloader for all .ejb3 files. Is that true? (I am using Jboss 4.0.3SP1 + EJB3_RC6)

Here is my test case:
EJB1:
Define a staleless session bean with name "CalculatorBean" which implements interface "Calculator"

EJB2:
Define another staleless session bean containing the following code:


Since EJB2 file doesn't contain any class with name "Calculator", I was assuming it will throw ClassNotFoundException at runtime. But it turns out everything works fine in EJB2. So I guess the session bean in EJB2 can access classes in EJB1 directly, is that true?
[ April 25, 2006: Message edited by: Yuan Ye ]
 
Andreas Schaefer
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Yuan

I am not 100% shure but JBoss needs to deploy each EJB3 file in its own classloader otherwise you would not be able to redeploy and that works here. Because I do not know how you deployed the application it is hard to figure out how your code works.
In general you would not get a ClassNotFoundException but a NoClassDefFoundError because your EJB2 has the Calculator referenced in its code and if it would be missing then it would be a linkage error. So somehow the Calculator class must be made available to EJB2.

-Andy
 
Yuan Ye
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Andy.

The way I deploy the jars(ejb3s) are the simplest way. Jar the classes and rename it to .ejb3(maybe not necessary) and copy them to deploy directory. Restart JBoss to pick them up. I also think JBoss should use one classloader per ejb3 file. But seems not true in this case. Here is an answer I got from Jboss Forum:
http://www.jboss.org/index.html?module=bb&op=viewtopic&t=81729

Unless you specify otherwise via the <loader-repository> element in jboss.xml, all classes in .jar (or .ejb3) files will be loaded into the same root classloader repository. You can use the <loader-repository> element to create child repositories per deployment - classes loaded into child repositories will not be visible outside of the particular deployment.


Did they change the implementation recently?
[ April 25, 2006: Message edited by: Yuan Ye ]
 
Andreas Schaefer
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Yuan

I do not quite understand the anwser but I think they are saying that all classes of a EJB3 archives is loaded by the same class loader.

Again I would need to see your achive layout to know what is going on.

-Andy
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See here. (BTW - we have a JBoss forum, which is more appropriate for this sort of question).
 
Yuan Ye
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After reading some articles, here is what I understand. JBoss is using different instances of class loaders to read different applications. However these classes are placed into a common repository which will be shared accross the AS. This explains why one class can access another class in a different jar. However in history(version 4.0), JBoss was using namespace + classname to store loaded classes, which disable such inter-application access, I guess.
To test, I created two jars. One jar contains a session bean which I can call through remote client. It is verified that within the session bean method, it can access a class which is only defined in the other jar. (Both jars are places under deploy directory)
Thanks Andy and Paul.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!