Search code examples
javawebsphereshared-libraries

understand the use of Websphere shared libraries vs. having libraries defined in your java project?


Can someone help me understand the use of Websphere shared libraries vs. having libraries defined in your java project? I'm new to websphere and don't understand the concept of shared libraries vs just putting the library classes in the lib folder in the project you are working on.


Solution

  • There are several benefits to using shared libraries:

    1. Reduce memory consumption. If you have many applications, using a server-associated shared library or isolated shared library allows the JVM to load a single copy of the classes in memory rather than loading the classes for each copy of the library in an application.
    2. Reduce the size of your WAR. This can improve deployment times, reduce network transfer, and reduce storage sizes if you keep backups.
    3. Improve manageability of environment. If you have many applications deployed and need to upgrade one of the libraries due to a fix, it can be more effort to repackage/redeploy many applications than to update a central library. If you need to update applications "slowly" rather than all at once, you can declare multiple shared libraries for different versions of the dependency; this approach obviously requires using application-associated rather than server-associated libraries, so you'll need to use an isolated shared library to still get the other benefits listed here.
    4. Better support for native libraries. If your application requires a library that uses native libraries and you package the library in your application, then you are typically unable to restart only your application without restarting the server since there is a JVM restriction that prevents native libraries from being unloaded or being loaded by multiple applications.

    The downside is that applications typically have tight coupling to the version of the library they are using, so separating the libraries from the application can make upgrades more difficult.