Websphere classloading issues
By: Sander Abbink, 18 September 2009Most of us who deploy on Websphere have at some point encountered classloading issues. Websphere provides a lot of libraries which are loaded by default (parent first) before the libraries supplied by the application. IBM explains the classloading order on this site:
http://www.ibm.com/developerworks/websphere/library/techarticles/0112_deboer/deboer.html
At my current position some Websphere installations have installed feature packs while others have not. You can view which feature packs are installed by running:
versionInfo.bat/sh from the Profile directory (e.g.: /opt/IBM/WebSphere/AppServer/profiles/AppSrv01/bin).
This can also cause version mismatches.
The following examples are from Websphere 6.1
Viewing classloader order:
You can view the order in which the libraries are loaded by following these links in the admin console:
Enterprise Applications > [ear module] > Manage Modules > [ war module] -> view module classloader.
You can expand the tree or export the contents of the Classloader viewer to a XML-file. Here you can easily tell if a library is provided by Websphere or your application.
Changing classloader order:
To change the classloading order follow the following link:
Enterprise Applications > [ear module] > Class loader
You can set the value of Class loader order to parent-last or application-first (depends on Websphere version) to make sure the jar-files of your application are loaded first. If the jar-files are also present in WEB-INF/lib you can alter the setting in:
Enterprise Applications >[ear module] > Manage Modules > [war module] (again parent-last or application-first)
If you cannot change these settings and you are deploying through WTP then you must change the file: application.xml. You can enter these settings at the deployment tab (maybe only in RAD?)
Creating your own classloader
Another way of preventing Websphere to load its own libraries first is to use a shared library.Jar-files in the shared-library are automatically placed on the classpath. You can create a special classloader to make sure certain libraries are loaded before anything else:
Application servers > server1 > Class loader
Select ‘new classloader’ and choose ‘Classes loaded with application class loader first’. After you have created this classloader you can attach your shared library to this loader. After this you can restart your application server for these changes to take effect. For me this is the cleanest solution but remember this affects all applications deployed on the server. The benefit is that you can change the classloading order on a per-library basis i.s.o. changing the order for all the libraries in the application.

19 September 2009 om 10:13 am
This is a common problem with JEE application servers. I`m afraid it`s only getting worse with Java EE 6 which has many many more libraries included in the app server.
The only way to solve the classloading/jar hell is to minimalize the number of pre-packaged libraries (e.g. reduce them to zero
). Or use a decent module system, OSGi maybe?
Btw, if you develop you apps with an IBM IDE then options are available for setting the classloader policy from Eclipse. But then again, who wants to use an IBM IDE
22 September 2009 om 8:59 pm
This week I also encountered strange WebSphere behavior. We’re running a third party application on a dedicated 8core/8GB AIX server with WAS 6.1. It had a 8GB heap size. Performance was really poor. It didn’t survive a single load test. Sysadmins in stress…
Until I asked them what garbage collection policy they were using. Well, that was gencon (a generational concurrent collector in IBM J9 VM).
But then I asked (since it was a generational GC) them what the sizes of the generations (young, old…) were.
It turned out that the maximum nursery space (young/eden generation) was 64MB, which is of course way too little, considering the total heap size of 8GB.
Increasing the nursery space to 1GB (-Xmn1G) did the trick.
Stupid that J9 picks such crappy defaults (their own documentation advises to configure the nursery space to 1/4 of the total heap size). HotSpot has much better defaults. It has an ergonomics feature, which adjusts performance settings based on your environment. Also, when you change a setting in HotSpot, other affected settings are auto-tuned appropriately.
When it comes to tuning, I like HotSpot more than IBM.