You can define a utility project as a shared library and associate defined shared
libraries with an application or web project.
Before you begin
To use the shared library function in the workbench, you must create a utility project and
define it as a shared library. The utility project is the only project type that can be used as a
shared library.
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 makes those classes available to the application or
module.
Procedure
To define a utility project as a shared library:
- Create a utility project:
- In the toolbar, select .
- Expand Java EE and select Utility
Project. Click Next.
- In the Project name field, specify a name for the utility
project.
-
Under the Ear membership section, clear the Add project to an
EAR check box.
-
Under the Target runtime section, verify that WebSphere® Application Server
Liberty is selected.
- Click Finish.
- Define the artifacts in the newly created utility project. For example, you can add Java classes to the utility project.
- Define the utility project as a shared library:
-
In the Project Explorer view, right-click the utility project and select .
- In the Shared library ID field, type a string as an identifier
for the shared library.
- In the Archive directory field, type or browse to a directory
where you want to place the compressed copy of your utility project as a JAR file. The file name
convention of the JAR file is utilityProjectName.jar, where
utilityProjectName is the name of the utility project.
-
In the Liberty Shared Library page, click Apply
to confirm your changes. Click OK to close the
Properties window.
- Optional:
Set the API visibility.
-
Right-click a utility 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.
-
Add the utility project to the server.
Results
Here is an example entry added to the server configuration (server.xml
)
file:<library id="libid">
<fileset dir="C:\temp" includes="Util.jar"/>
</library>
In addition, the JAR file is added in the specified archive directory. In
the previous example, the Util.jar
file is added in the
C:\temp directory.