facebook

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 andconsuming 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

This feature is available in MyEclipse.

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.

    menewmavenprojectc
    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.

    menewmavenconfigure
    Project configuration

2. Add a Java Maven Dependency to the Utility Project

  1. Right-click the utility project, and select Maven>Add Dependency.
  2. Type a dependency name in the Enter groupID… field (e.g., commons-logging) to search for a dependency.

    memavenadddependency
    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.
  5. View the Console. When it displays “Build Success,” the utility project is available for reference by other projects.

    memavenbuildsuccess
    Successful build

3. Add the Utility Project as a Dependency

  1. Right-click the consuming project, and select Maven>Add Dependency.
  2. In the Enter groupId… field, type com.mycompany or the group ID you entered when you created the utility project.

    memavenaddmydependency
    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.

    memaveneditconfig
    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.

meenablemavenfullindex

Enabling a full repository index