7

In Websphere, it is possible to create a "Shared Libraries" and associate with applications. I would want to know, in terms of position in classpath, what's the position of the shared libs are added? That means, I want to know, in case of duplicated resources, which will have higher "priority" to be loaded, Shared Libraries or the EAR/WAR itself.

For example, assume in my application, I have a resources called appConfig.xml, and I am creating a local directory in the app server, putting another appConfig.xml in that directory. If I tries to load the resources (e.g. open input stream) in my app, which file will be loaded?

I have searched for a while and can find nowhere mentioning this. Though I can try it out by myself by experimenting, I would want to know the official expected behavior, if any.

Thanks a lot

Adrian Shum
  • 38,812
  • 10
  • 83
  • 131

2 Answers2

8

The ordering amongst class loaders uses the so-called "class loader mode", which is either "parent first" (and application classes/resources last) or "parent last" (with application classes/resources first). For a single application class loader, the class path ordering will be:

  1. module class paths
  2. dependency class paths (Class-Path in MANIFEST.MF)
  3. shared library class paths

There is no configuration option to change the ordering. I do not think this ordering is explicitly state in documentation, but I also think it's highly unlikely to change. Regardless, I would not recommend relying on it. I would recommend ensuring you use unique resource/class names within a single class loader.

Brett Kail
  • 33,593
  • 2
  • 85
  • 90
  • 4
    Also when you've got doubts and want to know how the WAS is using the libraries you can use the "WebSphere web console –> Troubleshooting –> Class loader viewer" view on the WAS admin console. – MrJames Apr 04 '12 at 17:32
  • 2
    Yes, the class loader viewer can be useful for determining how the server happened to assemble things. It doesn't necessarily explain the rationale for the orderings. – Brett Kail Apr 04 '12 at 22:44
  • In fact I have read this before: http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/topic/com.ibm.websphere.soafep.multiplatform.doc/info/ae/ae/ucws_rsharedlib_inst.html Near the end there is a special section about "Use an isolated class loader for this shared library" and in this section, the ordering you gave is mentioned. Which I think it is a hint that, for normal shared library, it is not using a separated classloader for the shared libraries. Can someone verify if my understanding is correct? (If not, what's the diff between isolated class loader and normal shared lib?) – Adrian Shum Apr 05 '12 at 03:15
  • 1
    My fault. I missed the sentence "For a single application class loader". The reasoning I am concerning on this is, I want to make sure I can have a location in the server which I can put configuration files in, which can "shadow" the corresponding files in JARs, if any. It is especially important for log4j.xml which I encountered in my life that many 3rd party lib is including this file in the JAR, which makes it troublesome if the log4.xml from other lib is loaded before my locally configured one. – Adrian Shum Apr 05 '12 at 04:14
  • Unless you can ensure "parent first" will always be used, there's no convenient way to ensure an external .xml will always be first. If you can guarantee parent first, then either a server-associated shared library or an isolated shared library will work. – Brett Kail Apr 05 '12 at 04:54
  • 1
    To answer your shared library question: by default a shared library is appended to a class loader's class path; an isolated shared library is just that: it uses its own class loader that is "isolated" from the class loader to which the shared library is associated. – Brett Kail Apr 05 '12 at 04:55
1

I think here: http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=%2Fcom.ibm.websphere.express.doc%2Finfo%2Fexp%2Fae%2Fcrun_classload.html you'll find everything.

dpedro
  • 1,397
  • 1
  • 9
  • 8
  • Please refer to my comment in answer of @bkail . The question is not really that relevant to the classloader ordering. – Adrian Shum Apr 05 '12 at 04:16