How to add maven repository jars to eclipse buildpath?
Asked Answered
S

4

5

From eclipse I can see all the necessary jars in maven repositories view. But I have around 100 errors for the missing jar files. So I have set M2_REPO environment variable. I have ran the mvn eclipse:eclipse command from command line. When I run this command an ear package is added to one of subpackages of my project. For example my project name is portal. And sub package is portal_ear. The ear after running mvn eclipse:eclipse command is added to target folder of portal_ear. So my question is as I have the jars already in the repository, how can I add those to the portal buildpath inside eclipse?

Thanks.

Sketch answered 10/6, 2012 at 22:18 Comment(0)
P
3

Install m2e from the eclipse marketplace. You can now import existing maven projects into your workspace or convert existing ones.

Works very well for Eclipse 3.7

Palacio answered 10/6, 2012 at 23:42 Comment(0)
A
5

When you're using M2Eclipse, all you need to do is to make sure your Eclipse project is a Maven project. Select the project, click on "Convert > Convert to Maven project" or "Maven > Enable dependency management".

Do not manually add libraries. Also, the M2_REPO library variable is no longer used with m2eclipse, neither is to run the "mvn eclipse:eclipse" command. That is legacy you don't need to do any more.

You can also import your project by using "File > Import > Maven > Existing Maven project" and M2Eclipse will correctly set up the project's build path.

If you have custom Maven settings, such as an Enterprise Repository, you may want to tell M2Eclipse where to find your settings.xml file, if you do not have it in your user home but in the Maven installation (people do this sometimes). Go to "Window > Preferences > Maven > User Settings" and choose the right settings.xml.

Applause answered 10/6, 2012 at 22:31 Comment(2)
thanks for the reply. But when I write click -> maven there is no enable dependency management. There are some options e.g. update project config. , update dependencies, disable, etc. And also no option for conver. I am using eclipse indigo.Sketch
Then it's already a Maven project, use "Update Project Configuration". If this does not work as expected and you still miss dependencies in build path, either your Maven configuration is wrong (e.g. settings.xml) or you are manually adding classpath entries instead of using pom.xml.Applause
P
3

Install m2e from the eclipse marketplace. You can now import existing maven projects into your workspace or convert existing ones.

Works very well for Eclipse 3.7

Palacio answered 10/6, 2012 at 23:42 Comment(0)
J
3

In my case, I had an existing project that was deployed in Eclipse fine. Thank you Mkyong: http://www.mkyong.com/spring-security/spring-security-hello-world-example/

But when I needed to add JSTL for Logout tag support, I didn't see how to add the the jstl.jar file that was just pulled into my repo as another M2_REPO/xyz configuration. Instead, I could only import it as you would a regular .jar file - and that didn't seem right to me.

After reading a bunch of posts without success, I decided to see if I could get around the Eclipse UI and update the project configuration manually. From the project I opened .classpath in a text editor and added a new entry for the jar file:

<classpathentry kind="var" path="M2_REPO/javax/servlet/jstl/1.2/jstl-1.2.jar" sourcepath="M2_REPO/javax/servlet/jstl/1.2/jstl-1.2.jar">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>

Then I just refreshed my project in Eclipse (no restart required) and ...

  • the JSTL build error I was having in my JSP page went away
  • the build path entry for JSTL was appearing with the same M2_REPO as the other entries
  • the deployed code worked fine in Tomcat

Yes a bit of a hack, but still relatively clean I think - cheers

Jamesjamesian answered 21/8, 2013 at 20:13 Comment(0)
M
0

Right click on the project --> Maven --> Update Project...
For me it worked simply like that

Mada answered 4/12, 2019 at 10:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.