Customizing Project Dependencies

This topic describes advanced techniques for managing the location and availability of shared objects in your enterprise applications.

Web projects (web service or dynamic web projects) may have dependencies on either of the following:

These project linkages can be created in various ways. You can:

Making Utility Projects Available to Web Projects

All utility projects in an EAR project are automatically compiled into JARs that are copied into the APP-INF/lib directory of the deployed EAR.

As an alternative, you may specify that the utility project should be compiled into the WEB-INF/lib folder of a web project where it will be available only to that project.

A utility project can be added to more than one EAR project and available to more than one web project.

Option 1: Making Utility Projects Available to Web Projects at Project Creation

When creating a web services project or dynamic web project, if you choose Add project to an EAR on the first screen of the wizard, then any utility projects will be made available to the new project.

Note that if you did not choose Add project to an EAR on the first screen of the creation wizard, then you must add the project to an EAR manually.

The setting Add a dependency from this project to all Web projects in the EAR specifies that ALL of the utility and EJB projects will be available to this project when it is built. To make selective dependencies to specific projects, uncheck the Add a dependency from this project to all Web projects in the EAR option. You must then make any needed utility or EJB projects available explicitly.

Option 2: Adding a Utility Project to a Specific Web Project

When a utility project is already added to the EAR, you can add that utility project to a web project:

  1. Right click on the web services or dynamic web project name in the Project Explorer view and choose Properties from the popup menu. Click on J2EE Module Dependencies in the bar at the left. Be sure that the J2EE Modules tab is selected.
  2. Check the box beside the name of the utility project. Click Apply to save the change.

After the utility project is added, it will appear on the build path for this web project and the utility project types will be available in the IDE. Note that the Java Build Path option on the Properties dialog does not set up project dependencies correctly for Workshop projects. Adding a utility project to a web project means that the web project will access the shared copy of the utility module in the EAR. No files will be copied to the web project.

Note that the References to EJB JARs with EJB Client JARs box and the Use EJB JARs, Use EJB client JARs and Allow both buttons are not used by Workshop. Note also that EJB projects do not appear on the Web Libraries tab because EJBs are not libraries.

Option 3: Moving a Utility Project from an EAR Project to a Web Project

To add a utility project to a web project:

  1. Right click on the web services or dynamic web project name in the Project Explorer view and choose Properties from the popup menu. Click on J2EE Module Dependencies in the bar at the left. Be sure that the J2EE Modules tab is selected.

    Uncheck the box beside the name of the utility project. Click Apply to save the change.

    Note that the References to EJB JARs with EJB Client JARs box and the Use EJB JARs, Use EJB client JARs and Allow both buttons are not used by Workshop. Note also that EJB projects do not appear on the Web Libraries tab because EJBs are not libraries.
  2. Now click the Web Libraries tab. In the sample below, there is a new utility project which is not added to the current project.

  3. Click in the box beside the project name and click OK to add the new utility project to the existing project and make a virtual copy of its JAR file in the WEB-INF/lib folder of this project so that it will be available for build/deployment.

The J2EE Module Dependencies option is the recommended option for creating project dependencies in Workshop. Do not use the Java Build Path option to set project dependencies because it does not create all dependencies correctly.

Now you must stop the utility project from compiling into the EAR's APP-INF/lib directory by:

  1. Select the EAR project by clicking on the EAR project name in the Project Explorer view.
  2. Click Project > Properties and from the Properties dialog, click on J2EE Module Dependencies in the bar at the left.

  3. Click in the box beside the project name to REMOVE the check mark and click OK to remove the utility project from the EAR project.

Option 4: Adding A Utility Project from Outside the EAR

A utility project can also be added to a web project in an EAR even though the utility project is not added to the EAR itself. To do that:

  1. Right click on the web services or dynamic web project name in the Project Explorer view and choose Properties from the popup menu. Click on J2EE Module Dependencies in the bar at the left. Click the Web Libraries tab. In the sample below, there is a new utility project which is not added to the current project.

  2. Click in the box beside the project name and click OK to add the new utility project to the existing project and copy its JAR file to the WEB-INF/lib folder of this project on deployment.

Utility projects that are not added to the EAR can ONLY be added through the WEB-INF\lib folder of individual web projects.

Making EJBs Available to Selected Projects in an EAR

All EJB projects in an EAR project can be available to web services or dynamic web projects.

Option 1: Adding EJBs to Web Projects/Modules at Project Creation

When creating a web services project or dynamic web project, if you choose Add project to an EAR on the first screen of the wizard, then any EJB projects in the EAR will be made available to the new project.

To make selective dependencies to specific EJB projects, you must add any needed projects explicitly.

Option 2: Adding an EJB to a Web Project

If an EJB project has been added to an EAR, you can add the EJB project to web projects in the EAR by doing the following:

  1. Right click on the web services or dynamic web project name in the Project Explorer view and choose Properties from the popup menu. Click on J2EE Module Dependencies in the bar at the left. Be sure that the J2EE Modules tab is selected.

    Check the box beside the name of the EJB project. Click Apply to save the change.

Note that the References to EJB JARs with EJB Client JARs box and the Use EJB JARs, Use EJB client JARs and Allow both buttons are not used by Workshop. Note also that EJB projects do not appear on the Web Libraries tab because EJBs are not libraries.

Option 3: Making an EJB from Outside the EAR Available

If you are using a standalone EJB that is available at runtime on the WebLogic Server but not deployed with your EAR project, you must set it using the Java Build Path property page.

  1. Right click on the project name in the Project Explorer view and choose Properties from the popup menu. Click on Java Build Path in the bar at the left.

Note that the Java Build Path property page affects only Java source editing within the IDE. It does not affect deployment, exporting J2EE archive files, or generating Ant scripts.

Adding Web Projects to Multiple EAR Projects

If you have a web project that you use in more than one EAR, you can simply open each EAR project and link the project to that EAR.

When a project is a member of more than one EAR project, the Enterprise application project name pulldown box on the J2EE Module Dependencies property page will list the names of the EAR projects.

If a project is added to multiple EAR projects and you deploy more than one EAR project to the same server, there will be a name collision because there will be two copies of the same project deployed to the server. To eliminate the collision, you may undeploy one of the projects.

Alternately, you may open one of the EAR projects and edit the file EarContent/META-INF/application.xml . Change the value of the <context-root> element for the web project to a unique value. Changing this file is an advanced technique and should be done with care.

Making Application-Scoped Modules Available to the Server

If you want to ensure that application-scoped modules are deployed in the root of the EAR and available to the server at run time, you can do so by copying them to the following location:

EAR_PROJECT_ROOT/EarContent/META-INF

These modules should be mapped with a <module> element in the weblogic-application.xml file. The path to the module is a relative one, so be sure to include the META-INF portion of the path.

Related Topics

Configuring Standard Project Dependencies


Still need help? Post a question on the Workshop newsgroup.