WAS v8.5 > Administer applications and their environment > Administer the Liberty profile > Administer the Liberty profile manually > Configure class loaders and libraries for Java EE applicationsSharing a library across multiple Java EE applications
Libraries can be shared across multiple Java™ EE applications. All the applications can use the same classes at run time, or each application can use its own separate copy of those classes loaded from the same location. In the following example, a library called Haarlem consists of two files:
- haarlem-paintings.jar and
- commons-lang.jar
An application called Painter and an application called Student are running on a server called Academy, and both need access to this library.
- Create a lib/Haarlem directory in the servers/Academy directory under the ${WLP_USER_DIR} directory.
For example: wlp/usr/servers/Academy/lib/Haarlem.
- Copy the haarlem-painting.jar and commons-lang.jar files into the new folder.
- Configure class loading for the application, so the Haarlem library is loaded.
In server.xml, or an included file, define the library by adding the following code:
<library id="Haarlem"> < fileset dir="${server.config.dir}/lib/Haarlem" includes="*.jar" scanInterval="5s" /> </library>
The <library> element can also take a filesetRef attribute with a comma-separated list of < fileset> element IDs.
- Reference the library from the applications, so that both these applications share a single copy of the library.
In server.xml, or an included file, add the following code:
<application id="painter" name="Painter" type="ear" location="painter.ear"> < classloader commonLibraryRef="Haarlem" /> </application> <application id="student" name="Student" type="ear" location="student.ear"> < classloader commonLibraryRef="Haarlem" /> </application>The <commonLibraryRef> element can take a comma-separated list of library IDs.
- Optional: Configure another application to have its own set of classes loaded from the same JAR files.
For example, if another application called Spy needs its own copy of the classes, the same physical files on disk can be used. In server.xml, or an included file, add the following code:
<application id="spy" name="Spy" type="war" location="spy.war"> < classloader privateLibraryRef="Haarlem" /> </application>
The <privateLibraryRef> element can take a comma-separated list of library IDs.
Parent topic: Configure class loaders and libraries for Java EE applications
Related
Use a Java library with a Java EE application
Provide global libraries for all Java EE applications
Access third-party APIs from a Java EE application
Remove access to third-party APIs for a Java EE application
Overriding a provided API with an alternative version
Define a utility project as a shared library
Setting a web project to use shared libraries
|