I need to deploy multiple web services on a jax-ws application server, glassfish 3. These web services need to have shared libraries, meaning shared instances of the same class.
I know I could do this by dropping a jar in the “~/glassfish3/glassfish/domains/domain1/lib” directory. But I wonder whether this is possible in a more elegant way: I want to place the shared library jar inside a web service war which I deploy and then access that library from another war I deploy on the same application server.
How can I do this?
I found a solution for Glassfish myself: Basically I just deploy a class (
SharedClassLoader) which inherits fromURLClassLoaderas a shared library jar in the above mentioned directory. Then I use this classloader as a bootstrap: On calling the web service, the classloader hierarchy is extended as follows: ASharedClassLoaderfor an URL is instantiated if it does not exist yet and it is added as a delegate to theDelegatingClassLoaderin the classloader tree. By doing this for every web service with the sameSharedClassLoaderinstance, it acts as a bootstrap to pull in more class loading. The jar thatSharedClassLoaderrefers to can also be deployed with one of the web services, because Glassfish unpacks the containers to$AS_HOME/domains/domain1/applications/APPLICATION_NAME/LIBRARY_NAME.jar.I hope this helps anyone having the same problem. I solved this problem for my Bachelor Thesis. If anyone needs more information, just ask, I can send you my thesis.