More with “deploy –libraries” in GlassFish

A few months back Sahoo mentioned the use of "asadmin deploy --libraries" in the comments section as an effective way to deal with libraries. I recently had two people ask me about the behavior of GlassFish when multiple applications are deployed with --libraries pointing to the set jar file so I thought I’d share here what I found (this is for GlassFish v2.x). Thanks to Siva and Hong for the help there.

When multiple applications have --libraries pointing to the same jar, the classloading infrastructure tries to “share” the jar by loading it in the same classloader.

A side effect of this is that modifications to the jar require the undeployment and deployment of the application (along with its --libraries option) for it to use the updated version of the library. A simple deployment will trigger a ClassNotFoundException.

Note that it is your responsibility to keep track of all the applications using a given library and to do an undeploy/deploy for all of them as you may otherwise end up having different applications using different versions of the library.

The other option, which doesn’t require the keep track of the applications using a given library, is to update the library bits and simply restart the server. Of course that has other drawbacks…

Author: alexismp

Google Developer Relations in Paris.