简体   繁体   中英

I used m2eclipse plugins in eclipse.why the imported package still cannot be resolved by eclipse?

I get a mvn project , and to debug this project in eclipse,I imported the project into eclipse.But it's a pitty that some imported packages cannot be resolved by eclipse.Othes tell me that I should install m2eclipse plugin for eclipse, and run ""mvn eclipse:eclipse" to convert the project as a eclipse-like" project ,thus all packages will imported to eclipse build path automatically. Yes , I do so. And the eclipse build path is just like this

: 在此输入图像描述

But it is extremely strange that eclipse still cannot resolve some import .

在此输入图像描述

Any body can tell me what happened? From the build path ,I can see that eclipse have already imported the needed jar file for me.But it seems that the build path didn't take effect.

First of all, you're not using the m2e plugin; while it may be installed, it's not activated for this project:

  1. There is no little "M" on the project's icon
  2. The classpath doesn't include an entry org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER

From what I can see, Eclipse can't resolve the dependencies since the variable M2_REPO isn't defined (if it could, you would see the absolute path to the JARs in the upper image after the symbolic path).

To fix this, go to Preferences and search for "Classpath Variables". Add M2_REPO there with the correct path (default is $HOME/.m2/repository ).

If it already exists, make sure the path is correct.

Alternatively , right click on project and select " Convert to Maven Project " under " Configuration ".

How did u create a project. Try creating a web project. This template will provide the correct creation web application structure. It will also automatically add the required jars in the build path.

It is an eclipse problem (are you using the latest version?), try to run:

mvn eclipse:clean
mvn eclipse:eclipse

then open eclipse, refresh the project (right click on the project icon and select refresh ), clean it (Project > clean ...). It could be necessary to reconvert the project to maven (right click on the project and convert it to maven project). Sometimes closing the project (right click on the project icon > close project ) and reopening it (double click on the icon) solves this issue.

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