We are facing multiple class loading issue.
The class loader loads the class from some jar and next time its loads the same class from different jar.
We want to do something so that only specific class should get loaded from specific jar file.
Thanks
Swapnil
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12612
posted
0
There are at least two options:
1) Don't deploy multiple jars with the same class. Doing so means that unless you can specifically order the class resolution you're doomed to randomness.
2) Rename the class(es) inside one of the jars and update your code to use the new packaging (something like jarjar could do this).
#1 is better.
swapnl patil
Ranch Hand
Joined: Aug 13, 2007
Posts: 80
posted
0
I cant Adopt both the solution. Its our business requirement.so I want some handler or something which will load the class according to request.
This message was edited 1 time. Last update was at by swapnl patil
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12612
posted
0
As I said, unless you can precisely control classloader behavior, you cannot do what you want to do without (a) a sane deployment strategy, or (b) shading the classes in one of the two jars.
You *might* be able to write your own classloader and use that depending on your execution environment. Doing so is working around the problem rather than fixing it.
I'm pretty sure you don't mean "adobe".
Lester Burnham
Rancher
Joined: Oct 14, 2008
Posts: 1337
posted
0
If that is an actual business requirement -and I have a hard time believing that it is- then you should support it properly through the software. Either write your own classloader as David suggested, or use a framework like OSGi that gives you fine-grained control over which classes are loaded from which jar file, and which can cope with classes appearing in multiple jar files.
This message was edited 1 time. Last update was at by Lester Burnham
swapnl patil
Ranch Hand
Joined: Aug 13, 2007
Posts: 80
posted
0
Thanks Lester and David for reply.
xsunil kumar
Ranch Hand
Joined: Dec 14, 2009
Posts: 124
posted
0
Class loader works on some delegate principle. It means that if any jar is available in java lib or ext folder , then it will execute. If you are using web application, then you are ovveride this behaviour by putting jars in server lib.
For example
<Glass fish install dir>\domains\domain1\lib. Place that jar files which you want to make sure to excute at this location. Now your application will get jars from application server lib not from your own web-inf or ear lib.
Hope this will solve your issue. (only workaround).