aspose file tools*
The moose likes Servlets and the fly likes Class Loader, Common problem, Help!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Class Loader, Common problem, Help!!!" Watch "Class Loader, Common problem, Help!!!" New topic
Author

Class Loader, Common problem, Help!!!

Peter Kovgan
Ranch Hand

Joined: Sep 18, 2003
Posts: 84
I know it is a very common problem, but I can't find any complete answer for the question.
Please help me!
I am developing some application on some j2e platform, when I 'm doing lookup(from servlet, from bean or from jsp ,using some helper class) :
SomeClass c = (SomeClass)initCtx.lookup("name");
or by another method:
Object obj = initCtx.lookup("name");
SomeClass c = (SomeClass )PortableRemoteObject.narrow(obj,SomeClass .class);
lookup failed with ClassCastException
I know exactly what a problem: server loads SomeClass by particular class loader(CL1) and when I call
SomeClass from client another class loader(CL2) used.
I can't change class loader by which loaded object on server, then I must use anywhere CL1 to achieve
right casting.
How to do it?
I tried use Class.forName("SomeClass ",true,CL1);
I tried use CL1.loadClass("SomeClass")
but with these methods I only can receive Class object or createInstance(), but I can't keep reference to remote object.
What can I do to establish good casting???
Please, help!!!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

Casting won't help. Aside from the basic fact that the classes are loaded into different contexts, I think there are basic security issues that keep you from having classes from 2 different loader spaces work like that.
The solution is to place the class into a place where a copy can be loaded by the class context where you're calling. Usually this can be done by adjusting the classpath. Sometimes you have to move or copy files .
Because this is such a common - and frustrating problem, most appservers now clearly document what classloader constructions are used in the various differing parts of the system. When in doubt, consult the map.


Customer surveys are for companies who didn't pay proper attention to begin with.
Peter Kovgan
Ranch Hand

Joined: Sep 18, 2003
Posts: 84
Hi Tim!
Thank you for that idea.
-----------------------------------You write...
The solution is to place the class into a place where a copy can be loaded by the class context where you're calling. Usually this can be done by adjusting the classpath. Sometimes you have to move or copy files .
*******************************************
1. Which class I should place into particular place? The jar, which includes
lookup(ed) object?
I don't know where I should place my jar? Into server's lib directory?
Please, some explanation!!!
Thank you!!!
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Please don't post the same question in multiple places, it creates duplicate conversations. I'm going to ask for the other copy to be closed.
It would help if you said which app server you were using, there is a difference in the way their CassLoader heirarchies are arranged.
Dave
Peter Kovgan
Ranch Hand

Joined: Sep 18, 2003
Posts: 84
I'm using SAP's WAS.
 
 
subject: Class Loader, Common problem, Help!!!