简体   繁体   中英

How to add maven repository jars to eclipse buildpath?

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.

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.

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM