How do I add a Maven dependency in Eclipse?

Riley Lark picture Riley Lark · Feb 6, 2012 · Viewed 315.5k times · Source

I don't know how to use Maven at all. I've been developing for a couple years with Eclipse and haven't yet needed to know about it. However, now I'm looking at some docs that suggest I do the following:

"To include it within your project, just add this maven dependency to your build."

<repository>
   <id>jboss</id>
   <url>http://repository.jboss.org/maven2</url>
</repository>

   ...
<dependency>
   <groupId>org.jboss.resteasy</groupId>
   <artifactId>resteasy-jackson-provider</artifactId>
   <version>1.1.GA</version>
</dependency>

How do I do this with my Eclipse project?

Please assume I know nothing about Maven. I just figured out it might be installed on my computer by typing mvn on the command line, but that's seriously the extent of my knowledge. I would be happy to continue knowing nothing about Maven if there is an equivalent, non-Maven way of following these instructions with Eclipse.

Answer

Oded Breiner picture Oded Breiner · Oct 14, 2014
  1. On the top menu bar, open Window -> Show View -> Other
  2. In the Show View window, open Maven -> Maven Repositories

    Show View - Maven Repositories

  3. In the window that appears, right-click on Global Repositories and select Go Into

  4. Right-click on "central (http://repo.maven.apache.org/maven2)" and select "Rebuild Index"

    • Note that it will take a while to complete the download
  5. Once indexing is complete, Right-click on the project -> Maven -> Add Dependency and start typing the name of the project you want to import (such as "hibernate").

    • The search results will auto-fill in the "Search Results" box below.