How do I add a Maven dependency in Eclipse?
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.
- On the top menu bar, open Window -> Show View -> Other
- In the Show View window, open Maven -> Maven Repositories
- In the window that appears, right-click on Global Repositories and select Go Into
- Right-click on "central (http://repo.maven.apache.org/maven2)" and select "Rebuild Index"
- Note that it will take very long to complete the download!!!
- 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.
In fact when you open the pom.xml, you should see 5 tabs in the bottom. Click the pom.xml, and you can type whatever dependencies you want.
You need to be using a Maven plugin for Eclipse in order to do this properly. The m2e plugin is built into the latest version of Eclipse, and does a decent if not perfect job of integrating Maven into the IDE. You will want to create your project as a 'Maven Project'. Alternatively you can import an existing Maven POM into your workspace to automatically create projects. Once you have your Maven project in the IDE, simply open up the POM and add your dependency to it.
Now, if you do not have a Maven plugin for Eclipse, you will need to get the jar(s) for the dependency in question and manually add them as classpath references to your project. This could get unpleasant as you will need not just the top level JAR, but all its dependencies as well.
Basically, I recommend you get a decent Maven plugin for Eclipse and let it handle the dependency management for you.