Shared Java projects

There are two options for referencing shared Java classes from a web project:
  1. Create a single copy of the Java project JAR file in the EAR file. Each WAR file references the JAR file. This approach reduces the size of the EAR file.
  2. Create a copy of the JAR file in each WAR file. Use this approach if only one WAR file references the JAR file.

EAR-level library

Complete the following steps to place Java source files in a separate project:
  1. Create a new Java project and add the Java source code into the src folder of the project.
  2. Right-click the project in the Project view and select Properties.
  3. Select the Deployment Assembly item from the navigation pane. On the Ear Module Assembly pane, click Add to include the Java projects you want to reference.
    Figure 1. Java EE EAR module dependencies
    Ear Module Assembly pane
  4. Click OK to save your changes.

Web module library

To create a copy of the JAR file in each WAR file, complete the following steps:
  1. Right-click the project in the Project view and select Properties.
  2. Select the Deployment Assembly item from the navigation pane. On the Web Deployment Assembly pane, click Add to include the Java projects or archives you want to reference.
  3. Click OK to save your changes.