# WebLogic Shared Libraries

A WebLogic Shared Library is an Enterprise Application Archive, a stand-alone EJB, a Web Application module, or a JAR file that is registered with Oracle WebLogic Server as a shared library. The library resources can be shared between multiple applications, alleviating the need to have duplicate copies of the resources in each application. For an overview of WebLogic Shared Libraries, see "Deploying Shared Java EE Libraries and Dependent Applications" in Deploying Applications to Oracle WebLogic Server.

WebLogic shared libraries provide an easy way to share one or more types of Java EE modules among multiple applications.

A shared library can be one of the following:

- Stand-alone EJB module

- Stand-alone Web application module

- Multiple EJB modules packaged in an EAR file

- Multiple Web application modules packaged in a WAR file

- Single JAR file that is registered with the application container

After the library has been registered, you can deploy multiple applications that reference the library. Each referencing application can use the library as if it were packaged as part of the referencing application itself. The shared library classes are added to the classpath of the referencing application, and the referencing application's deployment descriptors are merged (in memory) with those of the library.

A registry of shared libraries can be viewed and edited using the workspace Preference page accessible through Window > Preferences > WebLogic > Shared Libraries. At run time, the registry is described in the domain's `config.xml` file.

These are terms used when working with WebLogic Shared Libraries:

Library reference: WebLogic Shared Libraries are referenced indirectly by specifying the name of the library, the specification version (optional), the implementation version (optional) and whether a newer version of the library should be used if present. The library references are used on the project classpath and in the deployment descriptors (`weblogic-application.xml` and `weblogic.xml`). Library references are resolved against the libraries registry when necessary.

Libraries registry (or registry): The list of known WebLogic Shared Libraries which is used to resolve a library reference.

## Common Operations

This section describes the following common operations associated with WebLogic shared libraries.

### Adding a New Library to the Registry

You can add new libraries to the registry.

To add a new library to the registry:

1. From the top-level menu, select Window > Preferences.

2. Find the WebLogic node in the tree on the left-hand-side of the dialog.

3. Select WebLogic > Shared Libraries from the list of preferences on the left.

4. Click Add.

5. Click Browse to select the library location.

6. Find the library archive where it is located on the disk, and select the library.

7. Verify the information presented in the Attributes section of the Add WebLogic Shared Library dialog. You can modify the library name, the specification version, and implementation version by using the Attributes table as long as they are not specified in the library's `manifest.mf` file.

8. Click OK.

### Adding a Library Reference to the Project Classpath

You can add a library reference to the project classpath.

To add a library reference to the project classpath:

1. Right-click on the project in the Project Explorer view and select Properties from the drop-down menu.This will open the Properties dialog.

2. In the Properties dialog, select the Java Build Path from the list of properties.

3. In the Java Build Path part of the dialog, select the Libraries tab.

4. Click Add Library.

5. Select WebLogic Shared Library, and then click Next.

6. Click Browse, and choose the library that you want to reference.

7. Modify the reference information, if necessary.

8. Click Finish.

### Modifying a Library Reference on the Project Classpath

You can modify library references.

To modify a library reference on the project classpath:

1. Select the project in the Project Explorer view.

2. Choose Project > Project Properties.

3. Locate the Java Build Path node in the tree on the left-hand-side of the dialog and select it.

4. Open the Libraries tab.

5. Find the entry in the list of libraries called Shared Library library-name and select it.

6. Click Edit.

7. Review the library reference. If any changes are necessary, make the changes and click Finish.

### Removing a Library Reference from the Project Classpath

You can remove library references.

To remove a library reference from the project classpath:

1. On the Properties dialog, select the Java Build Path from the list of properties.

2. On the Java Build Path part of the dialog, select the Libraries tab.

3. Find the entry in the list of libraries called Shared Library library-name, and then select it.

4. Click Remove.

## Validation Problems

This section lists error and warning messages that may appear in the Problems view. Resolutions are provided for each error/warning message.

### Validation Errors

- Unable to resolve library reference on project classpath

- Unable to resolve library reference in the deployment descriptor

- Library on classpath but not in weblogic-application.xml

- Library on classpath but not in weblogic.xml

- Web library referenced by a non-Web project

- Non-Web library referenced in weblogic.xml

- Project must be part of an EAR to use this library

- Project must be part of a web application to use this library

Unable to resolve the reference to "<library-name>" library on project classpath.

Problem: The library reference to a WebLogic Shared Library on the project classpath cannot be resolved using the workspace libraries registry. The project cannot be build.

Resolution 1: Add the appropriate library to the libraries registry. For instructions on how to do this, see Adding a new library to the registry.

Resolution 2: Modify the library reference to match what is present in the registry. For instructions on how to do this, see Modifying a library reference on the project classpath.

Resolution 3: Remove the library from the project classpath. For instructions on how to do this, see Removing a library reference from the project classpath.

Unable to resolve the reference to "<library-name>" library in the deployment descriptor.

Problem: The library reference to a WebLogic Java EE Library in the deployment descriptor (the `weblogic.xml` or `weblogic-application.xml` file depending on project type) cannot be resolved using the workspace libraries registry. The project many not run once deployed.

Resolution: Add the appropriate library to the libraries registry. For instructions on how to do this, see Adding a New Library to the Registry.

"<library-name>" library is on the classpath of this project, but is not in the weblogic-application.xml file of the EAR project "<EAR-project-name>".

Problem: The project contains a reference to a WebLogic Shared Library, but the weblogic-application.xml file of the EAR project that this project belongs to does not reference the library. This could lead to problems at run time since Oracle WebLogic Server will not know how to make this library available for use by this module.

Resolution: Remove the library from the project classpath. For instructions on how to do this, see Removing a Library Reference from the Project Classpath.

"<library-name>" library is on the classpath of this project, but is not in the weblogic.xml file.

Problem: The project contains a reference to a WebLogic Shared Library, but the weblogic.xml file does not reference this library. This could lead to problems at run time since Oracle WebLogic Server will not know how to make this library available for use by this module.

Resolution: Remove the library from the project classpath. For instructions on how to do this, see Removing a Library Reference from the Project Classpath.

"<library-name>" library is a web library and cannot be referenced by this project.

Problem: Oracle WebLogic Server only allows classes in a WAR-type WebLogic Shared Library to be visible to Web modules. While an EAR can reference such a library in the weblogic-application.xml, none of the classes in the referenced library will be visible to the classes in the EAR.

Resolution: Remove the library from the project classpath. For instructions on how to do this, see Removing a Library Reference from the Project Classpath.

"<library-name>" library reference is not allowed in the weblogic.xml file. Only WAR libraries are allowed.

Problem: Oracle WebLogic Server only supports WAR libraries to be referenced from the `weblogic.xml` deployment descriptor. A non-WAR library has been referenced in the descriptor.

Resolution: Remove the library from the weblogic.xml deployment descriptor.

This project must be part of an EAR in order to use "<library-name>" library.

Problem: The library referenced on the classpath of this project can only be accessed at run time if this project is part of an EAR and the EAR's `weblogic-application.xml` deployment descriptor references this library.

Resolution 1: Remove the library from the project classpath. For instructions on how to do this, see Removing a Library Reference from the Project Classpath.

Resolution 2: Create a new EAR project (or use an existing one). In the EAR project's Properties (right-click the EAR and select Properties) select the page labeled Java EE Module Dependencies. Select the project from the list, and then click Finish to associate the project with the EAR project.

This project must be part of a web application in order to use "<library-name>" library.

Problem: The library referenced on the classpath of this project can only be accessed at run time if this project is part of a Web application, and the Web application's `weblogic.xml` deployment descriptor references this library.

Resolution 1: Remove the library from the project classpath. For instructions on how to do this, see Removing a Library Reference from the Project Classpath.

Resolution 2: Create a new Dynamic Web project (or use an existing one). In the Web project's Properties (right-click the Web project, and select Properties) select the page labeled Java EE Module Dependencies. Select the Web Libraries tab. Select the project from the list, and then click Finish to associate the project with the Web project.

### Validation Warnings

This section lists warning messages that may appear in the Problems view. Resolutions are provided for each warning message.

- Classpath reference differs from weblogic-application.xml

- Classpath reference differs from weblogic.xml

The reference to the "<library-name>" library on this project's classpath differs from the reference to this library in the weblogic-application.xml file of the EAR project "<EAR-project-name>".

Problem: The library reference on the module project's classpath differs from the library reference in the `weblogic-application.xml` file of the EAR project that this module project belongs to. This could lead to problems at run time, because the project could be compiled against a different version of the library than what will be used at run time.

Resolution: Modify the library reference on the project classpath so it matches the library reference in the EAR project's weblogic-application.xml file. For instructions on how to do this, see Modifying a Library Reference on the Project Classpath.

The reference to the "<library-name>" library on this project's classpath differs from the reference to this library in the weblogic.xml file.

Problem: The library reference on this project's classpath differs from the library reference in the `weblogic.xml` file. This could lead to problems at run time, because the project could be compiled against a different version of the library than what will be used at run time.

Resolution: Modify the library reference on the project classpath so it matches the library reference in the `weblogic.xml` file. For instructions on how to do this, see Modifying a Library Reference on the Project Classpath.