• 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

Server and classloading

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,

I want to know how a JVM behavior have for jar classloading. For exemple if I have one class com.mypackage.myclass.class in a first jar like myjar1.jar and another version of this class in myjar2.jar how I can knowtry for force the second jar (myjar2.jar) class loading (overriding the first version in myjar1.jar). In what order jar are loaded into the JVM ?

I the myjar1.jar is loaded first and myjar2.jar is loaded in second, what the class version will be loaded ? The version in the first loaded jar myjar1.jar or myjar2.jar ?

Because, for example in a webapplication, several version of the same classes which can be present in differents jar, I want to force loading of specific versions of a jar that I know and where is present the last good version of classes.

Also, do you know is that possible or I need to override classloading ? And obviously how can I put this mechanism in place on different server (tomcat, jboss, websphere ...)

Great thanks and best regards,

Adrien
 
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think that behavior is defined anywhere, and I think it's reasonable to assume that it differs between JVMs and servers. So you need to assume that the wrong version will be loaded - which means you need to avoid this situation. While there are high-end solutions to this problem which add a fair amount of complexity (OSGi), maybe you can start by telling us why the web app needs to have different version of the same class.
 
ridaen fiefur
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes its differs between JVMs and Servers, but I don't know how to include OSGI into my webapp ... for the reason is very simple: several of ours client have already jar in WEB-INF/lib and don't want to have several classes under WEB-INF/classes, them prefer to have another jar included all modified classes (which can be already present under default ljars WEB-INF/lib)

The really question is, if a mechanism of class loading order can be know ? Like my webapp have to jar /myapp/WEB-INF/lib/myjar1.jar and /myapp/WEB-INF/lib/myjar2.jar (with the same classes) into the search path of URLs for loading classes and resources, how we can know if the classes will be loaded from myjar1 or myjar2 ? Alphabetical order ?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that it *can* be known because it is likely to be deterministic (it would be weird to do this randomly), and I recall reading at some time or other where someone said "server X does it this way". I don't think that would be documented anywhere, because it is a bad idea to rely on in. Analyzing the source code of the server would tell you for sure, assuming that it's available. It could be different for different server and/or JVM versions, obviously.

I don't quite understand the use case, though: you have a web app into which you add libraries provided by clients? I don't think it's a good idea to mix classes from various origins -which you seem to have no control over- in a single app; you may want to consider running separate web apps for the various clients - that accomplishes the desired separation. Or if that's not feasible for some reason, separate the client-provided classes from each other via OSGi. I think such a separation, however done, would be desirable from a security standpoint as well.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic