+

Search Tips   |   Advanced Search

Use a Java library with a Java EE application

Include Java libraries in an application.

In the following example, a library called Alexandria consists of two files:

An application called Scholar, running on a server called Academy, needs access to this library.

  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 the Alexandria library is loaded.

    In server.xml, 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>

    The <privateLibrary> element can also take a filesetRef attribute with a comma-separated list of <fileset> element IDs.


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

Tasks:

  • Share a library across multiple Java EE applications
  • 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