7

prefer-web-inf-classes has to be specified for the classes specified in Web-INF to take precendence over classes present in application library of weblogic server. I have a special case where I need the class loader to use one specific jar from WEB-INF folder. Is there any way of doing this?

Punter Vicky
  • 15,954
  • 56
  • 188
  • 315
  • Is this class an open source or 3rd party jar or your custom class? I'm wondering whether this class alone needs to be in the WEB-INF or can not the whole jar (including your class) be loaded from App classloader? – JoseK Nov 18 '11 at 06:00
  • Hi Jose,the specific jar is apache-commons-lang. I am sorry - it is a jar and not a class. Is there a way to do it? Thanks. – Punter Vicky Nov 18 '11 at 22:13
  • 1
    Not only for one jar from web-inf. The solution in this case is mgaert's answer. Move all other if possible into APP-INF and keep this one with a prefer-web-inf, else use package level entry in application.xml (i.e. Filtering Classloader) – JoseK Nov 21 '11 at 06:59

3 Answers3

5

To prefer all packages which are in your WEB-INF/lib over those which are bundled with your WebLogic lib set <prefer-web-inf-classes> to true in your weblogic.xml or application-weblogic.xml.

<container-descriptor>
    <prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>

For more detail see Using a Filtering Classloader, weblogic.xml Deployment Descriptor Elements and WebLogic's ClassLoaders, Filtering ClassLoader and ClassLoader Analysis Tool .

If you are not sure if the right class is loaded you can use the Classloader Analysis Tool for WebLogic.

Paul Wasilewski
  • 9,762
  • 5
  • 45
  • 49
  • For some reason the ClassLoader Analysis Tool (CAT) does not work. I receive an HTTP 503 error. I noticed the necessary wls-cat.war file is not included in the managed server deployment/installation like other managed servers on the weblogic container. ^_^ – user3808269 Feb 03 '20 at 20:05
3

You may want to look at Filtering Classloaders?

This allows to specify on a package-by-package level just which classloader to use.

You want to be very careful with this, though. Are you sure you already are in CLassloader Hell, so you must resort to this kind of stuff, and there's really no alternative?

Did you consider putting the JAR into the APP-INF/lib folder of your EAR? Or move "all but the one you need in WEB-INF/lib" out to APP-INF/lib?

mgaert
  • 2,338
  • 21
  • 27
  • Thanks mgaert. I just have a war file and it is not bundled into to ear. Is it possible to have filtering classloaders specify specific packages in WEB-INF\lib? – Punter Vicky Dec 28 '11 at 07:26
2

If you are using Weblogic 10.3.4+ version. You can use prefer-application-packages to control class level preference loading. Take a look at this video for more details.

Mani
  • 965
  • 6
  • 10