Search code examples
webspherewebsphere-7

How to change order of Jars loaded from WEB-INF/lib?


I am configuring a Java web module in WAS 7.0. I have all of my module JARs in the WEB-INF/lib directory and they are all loading. My problem is the order in which they load. I have 2 Jars: someJar.jar and aPatchForSomeJar.jar that are both located in WEB-INF/lib. aPatchForSomeJar.jar patches some classes that are found in someJar.jar. The problem is that someJar.jar is higher on the module classpath than the patch. This results in the classes in the original jar being used over the patched versions in the patched jar.

In my development environment (RAD 7.5 on win XP), the module classpath is loaded in alphabetical order (which results in aPatchForSomeJar.jar being loaded before someJar.jar). However, when deploying to a test environment (WAS 7.0 on GNU/Linux), it appears the module classpath is loaded in a random order (definitely not alphabetical at least) where the patch is loaded after the original Jar.

Does anyone know how I change the order in which WEB-INF/lib jars are loaded by the module?


Solution

  • As far as I know, there is no concept of alphabetical loading of jar files.

    Your packaging model needs to be revisited - packaging both the patch.jar and original.jar is going to cause you grief.

    Why do you need the original jar when the patch.jar contains the fixed ones?

    Even if you want to retain the original.jar and patch.jar (am assuming it is complete), you can try and use the class loader hierarchy to ensure that the patch.jar is loaded first compared to original.jar always.

    For e.g you can package original.jar at a shared library level with the class loading policy of parent_last and keep the patch.jar in your WEB-INF/lib.

    Though i am suggesting this as an alternative, you should consider replacing orginal.jar with the patch.jar or have the patch contain all the changed files (and removing them from the original.jar)

    HTH

    Manglu