Creating a Java Maven Dependency Project

This tutorial shows you how to create a generic Java Maven dependency project for consumption by a MyEclipse Web project, or any other Maven project. The steps cover basics of creating and consuming Maven dependencies. You will learn how to:

  • Create a Maven utility project
  • Add a dependency to a project
  • Add the utility project as a dependency

Duration Time: 20 Minutes

Start Tutorial Now

Don't have MyEclipse? Download Now


1. Create a Maven Utility Project

The Maven utility project will be consumed by an existing Maven project.

  1. Create a project with Maven support that will consume the project created in this tutorial.
  2. Select File>New>Project, type Maven in the search field, select Maven Project, and click Next.
    Java Maven dependency
    Creating a new Maven project
  3. Select the Create a simple project checkbox, and click Next.
  4. Enter group and artifact IDs and a project name, and click Finish.
    Java Maven dependency project
    Project configuration


2. Add a Java Maven Dependency to the Utility Project

  1. Right-click the utility project, and select Maven4MyEclipse>Add Dependency.
  2. Type commons-logging or other dependency in the Enter... field to search for a dependency.
    Adding a Java Maven dependency
    Selecting a dependency
  3. Select the dependency, and click OK.
  4. Expand the utility project, right-click the pom.xml file, and select Run As>Maven Install to install the file into the local repository.

    Installing the file into the local repository

When the console displays "Build Successful," the utility project is now available for reference by other projects.

Successful build


3. Add the Utility Project as a Dependency

  1. Right-click the consuming project, and select Maven4Myeclipse>Add Dependency.
  2. In the Enter... field, type com.mycompany or the group ID you entered when you created the utility project.
    Java Maven dependency
    Adding the utility project as a Java Maven dependency to the consuming project
  3. Select the utility project, and click OK. The dependency is added to the consuming project's pom.xml file.
  4. Right-click pom.xml file of the consuming project, and select Run As>Maven Build.
    Java Maven dependency
    Maven build configuration
  5. Select goals, and edit other build configurations as necessary, and click Run. Watch the console messages for a successful build message.

    Note: If you click the Select button to specify goals and the goals list is empty, you need to enable the full repository index. To do so, open the Maven Repositories view, and expand Global Repositories. Right-click Central, and select Enable Full Index. It will take several minutes for the indexes to update.

    Java Maven dependency
    Full repository index enabled