简体   繁体   English

我在eclipse中使用了m2eclipse插件。为什么导入的包仍然无法通过eclipse解决?

[英]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. 我得到了一个mvn项目,并在eclipse中调试这个项目,我将项目导入到eclipse中。但是eclipse有些导入的软件包无法解决这个问题。请告诉我,我应该为eclipse安装m2eclipse插件,然后运行“ “mvn eclipse:eclipse”将项目转换为类似eclipse的项目,因此所有包都会自动导入到eclipse构建路径中。 Yes , I do so. 是的,我这样做了。 And the eclipse build path is just like this eclipse构建路径就是这样的

: 在此输入图像描述

But it is extremely strange that eclipse still cannot resolve some import . 但是eclipse还是无法解决一些导入,这是非常奇怪的。

在此输入图像描述

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. 任何人都可以告诉我发生了什么?从构建路径,我可以看到eclipse已经为我导入了所需的jar文件。但是看起来构建路径没有生效。

First of all, you're not using the m2e plugin; 首先,你没有使用m2e插件; while it may be installed, it's not activated for this project: 虽然可能已安装,但此项目未激活:

  1. There is no little "M" on the project's icon 项目的图标上没有“M”
  2. The classpath doesn't include an entry org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER 类路径不包含条目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). 从我所看到的,Eclipse无法解析依赖关系,因为未定义变量M2_REPO (如果可以,您将在符号路径之后看到M2_REPO JAR的绝对路径)。

To fix this, go to Preferences and search for "Classpath Variables". 要解决此问题,请转到“首选项”并搜索“类路径变量”。 Add M2_REPO there with the correct path (default is $HOME/.m2/repository ). 使用正确的路径添加M2_REPO (默认为$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 ". 或者 ,右键单击项目,然后选择“ Configuration ”下的“ Convert to Maven Project ”。

How did u create a project. 你是如何创建一个项目的。 Try creating a web project. 尝试创建一个Web项目。 This template will provide the correct creation web application structure. 此模板将提供正确的创建Web应用程序结构。 It will also automatically add the required jars in the build path. 它还会自动在构建路径中添加所需的jar。

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 ...). 然后打开eclipse,刷新项目(右键单击项目图标并选择刷新 ),清理它(Project> clean ...)。 It could be necessary to reconvert the project to maven (right click on the project and convert it to maven project). 可能需要将项目重新转换为maven(右键单击项目并将其转换为maven项目)。 Sometimes closing the project (right click on the project icon > close project ) and reopening it (double click on the icon) solves this issue. 有时关闭项目(右键单击项目图标> 关闭项目 )并重新打开它(双击图标)解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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