For distributed platforms

Setting a web project to use shared libraries

If you have a utility project defined as a shared library, you can associate defined shared libraries with a web project.

Before you begin

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 application 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

  1. To set a web project to use shared libraries:
    1. In the Project Explorer view, right-click your web project that you want to associate shared libraries.
    2. Select Properties > Liberty Profile Shared Libraries.
    3. 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
      Tip: The shared library identifier is the value specified in the Shared Libary ID field from the Defining a utility project as a shared library task.
      Restriction: A shared library cannot be added to an application that is already deployed on a server. To add a shared library, remove the application from the server, add the shared library, and then re-deploy the application to the server. For more information about shared libraries see Defining a utility project as a shared library.
  2. You might want to add its associating utility projects to the class path for compilation-purpose:
    1. In the Project Explorer view, right-click your project that you are associating shared libraries.
    2. Select Properties > Java Build Path.
    3. Select the Projects tab.
    4. Click Add.
    5. Select the utility projects that the project references.
  3. 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.
  4. Add the web project to the server. For more details see Adding and running an application on the Liberty profile by using developer tools topic.

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>

Icon that indicates the type of topic Task topic

Terms and conditions for information centers | Feedback


Timestamp icon Last updated: Wednesday, 22 May 2013
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=phil&product=was-nd-mp&topic=t_associate_shared_library
File name: t_associate_shared_library.html