Use a Java library with a Java EE application


Overview

Including libraries in the application itself might not always be desirable or appropriate, especially if the application is already packaged and does not include the library.

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

  • alexandria-scrolls.jar
  • commons-lang.jar

We will give an application called Scholar, running on a server called Academy, access to this library.


Steps

  1. Create directory...

  2. Copy alexandria-scrolls.jar and commons-lang.jar into the new directory.

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

    Note that 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


Related tasks