The shared library feature in WebLogic Server provides an easy way to share one or more different types of JEE modules among multiple Enterprise Applications. You have two main options for sharing a library across your domain applications: you can either drop the library into the DOMAIN_HOME/lib or deploy the application itself as a library.
The domain library directory (lib) is one mechanism that can be used for adding application libraries to the server classpath. The jars located in this directory will be picked up and added dynamically to the end of the server classpath at server startup. The jars will be ordered lexically in the classpath.
It is possible to override the DOMAIN_HOME/lib directory by using the -Dweblogic.ext.dirs system property during startup. This property specifies a list of directories to pick up jars from and dynamically append to the end of the server classpath using java.io.File.pathSeparator as the delimiter between path entries.
Beware that, once you put your libraries in the DOMAIN_HOME/lib directory, you have to restart the server when the jar changes.
The deployment process is discussed in detail in Chapter 8 of this book. Anyway, deploying a new application as shared library requires following a very simple procedure:
- Open the Admin Console and click on Deployments. Once in the Deployment Summary screen, click on the Install button.
- Browse to your deployments and, once selected, you can opt to install it as an application or as library. Choose: “Install the deployment as a library”
Once completed the deployment, you will have a deployment view of your library which resembles the following example:
Applications can reference shared libraries by adding a library-ref element into the WebLogic custom deployment descriptors. For example, the following entry in the weblogic.xml references the above shared library named SharedLib:
The main difference from barely adding files to the classpath is that a shared library can actually be a Java EE application. Working with a shared library gives you also more flexibility since you are able to deploy multiple versions of the library and use deployment descriptors to refer to the right version. You can include library specifications in the META-INF/MANIFEST.MF file:
Here’s the deployment outcome on the WLS console, when deploying the Shared Library application including the above library specifications:
And here’s how to reference an exact version in your weblogic.xml file:
- << Prev