Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple class loading issue

 
swapnl patil
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
swapnl patil
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Lester and David for reply.
 
xsunil kumar
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).

-Sunil
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic