• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EJB access and classloader

 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic