This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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.
Joined: Aug 13, 2007
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.
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.
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.
<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).