Adding libraries to the EAR library directory

About this task

Important: Applicable to Liberty, WebSphere® Application Server traditional

Procedure

  1. Open the pom.xml file in the POM editor by double-clicking the file. Click the pom.xml tab to work directly with the source.
  2. Set the lib directory to be used in the EAR project.
    Add the element <defaultLibBundleDir> to the configuration of the maven-ear-plugin as in this example:
    <plugins>
       <plugin>
          <artifactId>maven-ear-plugin</artifactId>
          <version>2.7</version>
          <configuration>
             <version>6</version>
             <defaultLibBundleDir>lib</defaultLibBundleDir>
          </configuration>
       </plugin>
    </plugins>
  3. Save the pom.xml file.
  4. Use quick fixes to resolve any errors.
    After you save the pom.xml file, you might see the following errors in the Problems or Markers view:
    • Library Directory "<PATH_TO_LIB_FOLDER>" does not exist.
    • Project configuration is not up-to-date with pom.xml. Run Maven->Update Project or use Quick Fix.
    Right-click the errors and select Quick Fix to resolve the errors.
  5. Place JAR files in the lib directory.
    If the lib directory is specified for the EAR project in the <defaultLibBundleDir> element, then all dependencies to JAR artifacts are bundled in the lib directory by default. However, if you want to place a JAR file in a different location, you can use the <jarModule> element to specify a different location.
    For example, the following fragment of pom.xml shows that the EAR project uses lib as the default directory to bundle JAR files:
    <plugin>
       <artifactId>maven-ear-plugin</artifactId>
       <version>2.7</version>
       <configuration>
          <version>6</version>
          <defaultLibBundleDir>lib</defaultLibBundleDir>
    In the following example, the pom.xml file has a dependency to a shared library that is packaged in lib and a dependency to an EJB client JAR file that is bundled at the root of the EAR file. Without further changes, both are bundled in the lib directory by default.
    <dependencies>
      	<dependency>
          <groupId>testapp</groupId>
          <artifactId>ejbclient</artifactId>
          <version>0.0.1-SNAPSHOT</version>
       </dependency>
       <dependency>
          <groupId>testapp</groupId>
          <artifactId>SharedLib</artifactId>
          <version>0.0.1-SNAPSHOT</version>
       </dependency>
    </dependencies>
    The following example shows how to change the location of the EJB client JAR file:
    <plugin>
       <artifactId>maven-ear-plugin</artifactId>
       <version>2.7</version>
       <configuration>
          <version>6</version>
          <defaultLibBundleDir>lib</defaultLibBundleDir>
          <modules>
             <jarModule>
                <groupId>testapp</groupId>
                <artifactId>ejbclient</artifactId>
                <bundleDir>/</bundleDir>
             </jarModule>
          </modules>
       </configuration>
    </plugin>
    This example shows that the default bundle directory for JAR files is lib, but the EJB client JAR file for <artifactId>ejbclient</artifactId> is in the root of the project. The bundle directory is indicated with <bundleDir>/</bundleDir>.