IBM Support

Specifying external dependencies to applications running on WebSphere Application Server Community Edition

Troubleshooting


Problem

Applications can have dependency for external libraries in the form of jar files or zipped archives. This document details the steps to specify external dependencies to applications running on WebSphere® Application Server Community Edition.

Resolving The Problem

There are 3 ways by which external dependencies can be specified for applications.

  • Specifying dependencies by adding to repository
  • Use the Shared Library feature
  • Specifying dependencies stored outside the application server directory by adding a GBean to deployment plan

Specifying dependencies by adding to repository
  1. Launch the Administrative Console.

  2. Open the Add Archive to Repository wizard.
    • Choose Common Libs under Services.

    • Repository Viewer is displayed with Add Archive to Repository wizard.

  3. Fill the form as shown in the screen shot below. Add the dependency using Install after filling the form.

    The example shows the steps to add sample.jar as a dependency.


  4. Note: Change the Version field to add a different version of the same jar file.

  5. On successful installation the newly added jar, car or rar will be displayed in Repository Viewer under Current Repository Entries.

  6. Choose the newly added entry to view usage of dependency in an application or module.

  7. Add a dependency element under dependencies in environment element in the deployment plan as shown below.



Steps to add external dependency using Shared Library
  1. Copy zip or jar files to <Installation_Directory>/var/shared/lib
  2. Add a dependency on artifact sharedlib in the deployment plan as follows.

  3. <environment>
    ...
      <dependencies>
      ...
        <dependency>
          <artifactId>sharedlib</artifactId>
        </dependency>
      </dependencies>
    </environment>  


Specifying dependencies outside the application server directory
To add libraries located outside application server directory you need to add a GBean element to the deployment plan of the application.
  • Consider a sample application which refers to two directories for dependencies C:\mylib1\myjarfile1.jar and C:\mylib2\myjarfile2.jar

  • Add gbean in the deployment plan to specify the dependency as follows:

  • ...
    <context-root>MyApp</context-root>
    <gbean name="SharedLib1" class="org.apache.geronimo.system.sharedlib.SharedLib">
    <attribute name="libDirs">
    c:/mylib1,c:/mylib2</attribute>
    <reference name="ServerInfo">
    <name>ServerInfo</name>
    </reference>
    </gbean>
    ...
    </web-app>

To add non-library files (ones which are not packaged in a .jar) like .properties files located outside application server directory you need to add a GBean element to the deployment plan of the application.
  • Consider a sample application which refers to a property file for dependencies C:\myProperty\sample.properties

  • Add gbean in the deployment plan to specify the dependency as follows:

  • ...
    <context-root>MyApp</context-root>
    <gbean name="SharedLib1" class="org.apache.geronimo.system.sharedlib.SharedLib">
    <attribute name="classesDirs">C:/myProperty</attribute>
    <reference name="ServerInfo">
    <name>ServerInfo</name>
    </reference>
    </gbean>
    ...
    </web-app>

Note: The dependency specified by adding to repository is useful when we want the application to use a particular verison of the library. For example, if there are com/foo/1.0/mylib.jar and com/foo/1.1/mylib.jar libraries and your application requires the latest as a dependency then use the copy to repository method so that you can specify the version you require.

The dependency specified by shared library is useful when we have multiple applications using multiple set of libraries. In this case it becomes cumbersome to add dependency element for each library in each application deployment plan

[{"Product":{"code":"SS6JMN","label":"WebSphere Application Server Community Edition"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"General","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF016","label":"Linux"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"2.1.1.2;2.1.1.1;2.1.0.1;2.1;2.0.0.3;2.0.0.2;2.0.0.1;2.0;1.1.0.2","Edition":"Entry;Enhanced;Elite","Line of Business":{"code":"LOB45","label":"Automation"}}]

Document Information

Modified date:
15 June 2018

UID

swg21266061