Providing global libraries for all Java EE applications
You can provide global libraries that can be used by any Java™ EE application. You do this by putting the JAR files for those libraries in a global library directory, then specifying use of global libraries in the class loader configuration for each application. However, the global libraries cannot be used by other applications, for example, by OSGi applications.
The latest documentation about class loader configuration for Liberty is available on the Open Liberty website.
About this task
Under the user directory specified by using the environment variable
WLP_USER_DIR
, there are the following locations in which you can place global libraries:- ${shared.config.dir}/lib/global
- ${server.config.dir}/lib/global
<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 you use global libraries, you 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 the
server.xml
file, 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 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>