If you have a utility project defined as a shared library, you can associate defined
shared libraries with a web project.
About this task
A shared library is an external Java™ archive (JAR)
file that is used by one or more applications. Using shared libraries enables multiple applications
published on a server to use a single library, rather than use multiple copies of the same library.
After you associate shared libraries with an application or project, the application or module class
loader loads classes in the shared libraries and make those classes available to the application or
module.
Procedure
- To set a web project to use shared libraries:
- In the Project Explorer view, right-click your web project that
you want to associate shared libraries.
-
Select .
-
When you click the Add button, a list of shared library IDs appears. In the
IDs field, specify one or more shared library identifiers that you want the
project to reference. To specify multiple identifiers, use a comma-separated list. For example: ID1,
ID2, ID3.
- You might want to add its associating utility projects to the class path for
compilation-purpose:
- In the Project Explorer view, right-click your project that you
are associating shared libraries.
- Select .
- Select the Projects tab.
- Click Add.
- Select the utility projects that the project references.
- Optional:
Set the API visibility.
-
Right-click a web project.
-
Select .
-
Select from the following check boxes to set the API visibility: API,
IBM API, Spec, and Third party.
The default visibility is set for API, IBM API, and
Spec.
- Develop the artifacts in the web project. For example, you can add a servlet in a web
project that references classes in the shared libraries.
-
Add the web project to the server.
Results
Here is an example entry added to the server configuration (server.xml
)
file:<application type="war" id="web" name="web" location="web.war">
<classloader commonLibraryRef="libid"/>
</application>