There are several benefits to using shared libraries:
- 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.
- Reduce the size of your WAR. This can improve deployment times, reduce network transfer, and reduce storage sizes if you keep backups.
- 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.
- 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.