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.
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
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
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 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>