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
- Create directory...
-
${WLP_USER_DIR}/servers/Academy/mylib/Alexandria
- Copy alexandria-scrolls.jar and commons-lang.jar into the new directory.
- 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
- Sharing a library across multiple Java EE applications
- Providing 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
- Configure the web module class loader for an enterprise application
- Class loader configuration