Using a Java library with a Java EE application

One way of using Java™ libraries with an application is to include them in the application itself. This might not always be desirable or appropriate, especially if the application is already packaged and does not include the library.

Open Liberty The latest documentation about class loader configuration for Liberty is available on the Open Liberty website.

About this task

In the following example, a library called Alexandria consists of two files:
  • alexandria-scrolls.jar and
  • commons-lang.jar
An application called Scholar, running on a server called Academy, needs access to this library.

Procedure

  1. Create a mylib/Alexandria directory in the servers/Academy directory under the ${WLP_USER_DIR} directory.

    For example: wlp/usr/servers/Academy/mylib/Alexandria.

  2. Copy the alexandria-scrolls.jar and commons-lang.jar files into the new folder.
  3. Configure class loading for the application, so that the Alexandria library is loaded.
    In the server.xml file, or an included file, add the following code:
    <application id="scholar" name="Scholar" type="ear" location="scholar.ear">
      <classloader>
        <privateLibrary>
          <fileset dir="${server.config.dir}/mylib/Alexandria" includes="*.jar" scanInterval="5s" />
        </privateLibrary>
      </classloader>
    </application>
    
    Note: The <privateLibrary> element can also take a filesetRef attribute with a comma-separated list of <fileset> element IDs.