141

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.

Stevoisiak
  • 16,510
  • 19
  • 94
  • 173
Riley Lark
  • 19,952
  • 14
  • 75
  • 122
  • 2
    Have you read the Maven Starting Guide: http://maven.apache.org/guides/getting-started/index.html – Dan W Feb 06 '12 at 18:08
  • 4
    The non-Maven equivalent: Find all libraries that you need and add them to your project's build path (lib directory). "All libraries that you need" = resteasy-jackson-provider-1.1.GA.jar (2.3.0 is the current version...) plus all dependencies. "All dependencies" is what Maven does for you (in this situation). Looking it up they are jackson-core-asl, jackson-mapper-asl, jackson-jaxrs, jackson-xc. Learn a little Maven, it is absolutely worth the time. – Hauke Ingmar Schmidt Feb 06 '12 at 18:17
  • You will find more information about Maven in the [Maven: The Complete Reference](http://www.sonatype.com/books/mvnref-book/reference/) guide, and you should also consider to install the Eclipse [M2E](http://wiki.eclipse.org/Maven_Integration) plugin (previously known as m2eclipse). – matsev Feb 06 '12 at 18:17

6 Answers6

214
  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

  1. In the window that appears, right-click on Global Repositories and select Go Into
  2. 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!!!
  1. 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.
Oded Breiner
  • 25,024
  • 9
  • 99
  • 66
28

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.

enter image description here

DoraShine
  • 611
  • 1
  • 6
  • 11
  • helped me out big time. didnt notice the 5 tabs before – M. Smith May 25 '16 at 19:33
  • 2
    Eclipse still doesn't recognize the dependencies from my pom.xml in my code. When I use IntelliJ it automatically downloads them and sets them up for code completion, doesn't eclipse do this? – Cas Eliëns Aug 31 '16 at 13:47
  • If you already know the details of your dependency (group id, artifact id, version), then this is *much* faster than downloading the Internet just to include `my-favorite-library.jar` in your project. – Christopher Schultz Jul 12 '17 at 19:08
11

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.

Perception
  • 75,573
  • 19
  • 170
  • 185
  • 2
    Thanks for the answer. I already have a project with 1000 files in it - is there a way to *add* maven support, instead of starting from scratch? I have the latest version of Eclipse – Riley Lark Feb 06 '12 at 18:58
  • 3
    With the latest version of Eclipse and m2e you can right click on a regular Java project and enable Dependency Management for it. This will generate a pom.xml for the project, while leaving its structure intact. – Perception Feb 08 '12 at 05:40
9

Open the pom.xml file.

under the project tag add <dependencies> as another tag, and google for the Maven dependencies. I used this to search.

So after getting the dependency create another tag dependency inside <dependencies> tag.

So ultimately it will look something like this.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>doc-examples</groupId>
  <artifactId>lambda-java-example</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>lambda-java-example</name>
  <dependencies>
      <!-- https://mvnrepository.com/artifact/com.amazonaws/aws-lambda-java-core -->
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-lambda-java-core</artifactId>
        <version>1.0.0</version>
    </dependency>
  </dependencies>
</project>

Hope it helps.

driftking9987
  • 1,499
  • 1
  • 24
  • 51
2

I have faced the similar issue and fixed by copying the missing Jar files in to .M2 Path,

For example: if you see the error message as Missing artifact tws:axis-client:jar:8.7 then you have to download "axis-client-8.7.jar" file and paste the same in to below location will resolve the issue.

C:\Users\UsernameXXX.m2\repository\tws\axis-client\8.7(Paste axis-client-8.7.jar).

finally, right click on project->Maven->Update Project...Thats it.

happy coding.

Blasanka
  • 14,208
  • 6
  • 76
  • 90
  • Thanks! This was not my specific problem but it helped me solve it. In my case my jar was in the correct location but the path was slightly wrong. – Captain Fantastic Apr 27 '18 at 13:48
-1

I have faced same problem with maven dependencies, eg: unfortunetly your maven dependencies deleted from your buildpath,then you people get lot of exceptions,if you follow below process you can easily resolve this issue.

 Right click on project >> maven >> updateProject >> selectProject >> OK