+

Search Tips   |   Advanced Search

Provide global libraries for all Java EE applications

Put the JAR files for those libraries in a global library directory, then specify use of global libraries in the class loader configuration for each application. The global libraries cannot be used by other applications, for example, by OSGi applications.

Under the user directory specified using the environment variable WLP_USER_DIR, there are the following locations in which we can place global libraries:

If there are files present in these locations at the time an application is started, and that application does not have a <classloader> element configured, the application uses these libraries. If a class loader configuration is present, these libraries are not used unless the global library is explicitly referenced.

Attention: If we use global libraries, we are advised also to configure a <classloader> element for every application. The servlet specification requires applications to share the global library class loader in their class loader parent chain. This breaks the separation of class loaders for each application that is otherwise possible. So, applications are more likely to have long-lasting effects on classes loaded in Liberty and on each other, and class space consistency issues are more likely to arise between applications, especially as features are added and removed from a running server. None of these considerations apply for applications that specify a <classloader> element in their configuration, because they maintain this separation.


Example

In the following example, an application called Scholar is configured to use a common library called Alexandria, and also to use the global library.

In server.xml, or an included file, enable the global library for an application by adding the following code:

<application id="" name="Scholar" type="ear" location="scholar.ear">
  <classloader apiTypeVisibility="spec" commonLibraryRef="Alexandria, global" />
</application>

The settings for the global library can also be configured explicitly, as a library element with the special ID global. For example:

<library id="global">
  <fileset dir="/path/to/folder" includes="*.jar" />
</library>


Parent topic: Configure class loaders and libraries for Java EE applications

Concepts:

  • Shared libraries

    Tasks:

  • Use a Java library with a Java EE application
  • Share a library across multiple 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
  • Customize the Liberty profile environment