Eclipse 项目中缺少 Maven 依赖项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4262186/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Missing Maven dependencies in Eclipse project
提问by hostnik
We have a project set up with maven for resolving dependancies. It usually works fine, but now I am trying to compile and run it on a new PC and I have problem with missing dependencies in Eclipse.
我们有一个用 maven 设置的项目来解决依赖关系。它通常工作正常,但现在我试图在新 PC 上编译和运行它,但我遇到了 Eclipse 中缺少依赖项的问题。
What is funny is that if I run "mvn package" in console or in eclipse, it works fine and even produces war containing all necessary jars. Only Eclipse complains with "The project was not built since its build path is incomplete. Cannot find the class file for org.slf4j.Logger...". If I compare the project with some other computer (where project works fine), I notice that there are quite a few libraries missing under "Maven dependencies" listing in Eclipse. Eventhough they are in the packaged war and they can be found also under repository folder.
有趣的是,如果我在控制台或 eclipse 中运行“mvn package”,它运行良好,甚至会产生包含所有必要 jar 的War。只有 Eclipse 抱怨“该项目未构建,因为其构建路径不完整。找不到 org.slf4j.Logger 的类文件...”。如果我将项目与其他计算机(项目工作正常)进行比较,我会注意到在 Eclipse 中的“Maven 依赖项”列表下缺少很多库。即使它们在打包的War中,它们也可以在存储库文件夹下找到。
So, the jar-s are there just Eclipse won't list them all under "Maven dependencies". What can I do?
因此,jar-s 在那里只是 Eclipse 不会在“Maven 依赖项”下列出它们。我能做什么?
Computer is running on Windows 7 with 64bit java & eclipse.
计算机在带有 64 位 java 和 eclipse 的 Windows 7 上运行。
采纳答案by hostnik
Problem solved!
问题解决了!
I don't know what exactly solved it, but I did 4 things in Eclipse:
我不知道究竟是什么解决了它,但我在 Eclipse 中做了 4 件事:
- Window->Preferences: Maven->Installations: Global settings -> open file and hardcoded localRepository
- Project->Clean
- right click on project: Maven->Update dependencies
- right click on project: Maven->Update project configuration
- 窗口->首选项:Maven->安装:全局设置->打开文件和硬编码的localRepository
- 项目->清洁
- 右键单击项目:Maven->更新依赖项
- 右键单击项目:Maven->更新项目配置
I guess it was the Update dependencies since right after first two there were no change.
我想这是更新依赖项,因为在前两个之后没有变化。
回答by Ualter Jr.
Well, I tried everything posted here, unfortunately nothings works in my case. So, trying different combinations I came out with this one that solved my problem.
好吧,我尝试了这里发布的所有内容,不幸的是在我的情况下没有任何效果。所以,尝试不同的组合,我想出了这个解决了我的问题的组合。
1) Open the .classpathfile at the root of your eclipse's project.
1) 打开eclipse项目根目录下的.classpath文件。
2) Insert the following entry to the file:
2) 在文件中插入以下条目:
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
Then, rebuild your project at eclipse (Project->Clean-Build).
You now can check at the Java Build Path of you project at the Libraries tab the Maven Dependencies included:
然后,在 eclipse 中重建你的项目(Project->Clean-Build)。您现在可以在包含 Maven 依赖项的库选项卡中检查项目的 Java 构建路径:
回答by rogueleaderr
I'm also new to Eclipse, and I've been having a similar problem where Eclipse just won't recognize an import statement, even though all signs point to the dependency having been successfully downloaded.
我也是 Eclipse 的新手,我遇到了类似的问题,即 Eclipse 无法识别导入语句,即使所有迹象都表明依赖项已成功下载。
You should check that your dependency file has actually been downloaded by going to the command line and typing
您应该通过转到命令行并键入来检查您的依赖文件是否已实际下载
mvn dependency:tree
mvn dependency:tree
If you see your package there, then but Eclipse doesn't acknowledge it, the thing that works for me (sometimes) is to go to the terminal, cd into the project folder, and type
如果你在那里看到你的包,但 Eclipse 不承认它,对我有用的事情(有时)是转到终端,进入项目文件夹,然后键入
mvn eclipse:clean
then
mvn eclipse:eclipse
mvn eclipse:clean
然后
mvn eclipse:eclipse
Finally refresh project in eclipse
最后在eclipse中刷新项目
I don't know why this works, and sometimes it doesn't work once, then doing it again does work... so worth a try!
我不知道为什么这有效,有时它一次不起作用,然后再做一次确实有效......所以值得一试!
回答by Joseph Lust
My Project was just screwed up. Here is how I fixed it for Eclipse Indigo x64 (J2EE 3.7.3):
我的项目刚刚搞砸了。以下是我为 Eclipse Indigo x64 (J2EE 3.7.3) 修复它的方法:
- Deleted my POM file (backedup of course).
- Project Context Menu> Maven> Disable Maven Nature.
- Deleted the project (but not contents on disk).
- Re-imported as Import> General> Existing Project.
- Project Context Menu> Configure> Convert to Maven Project....
- Accept defaults from Maven wizard.
- Overwrite POM with your backedup POM. (Now you have Maven Dependencies folder).
- Maven Update/Clean for good measure.
- 删除了我的 POM 文件(当然是备份的)。
- 项目上下文菜单> Maven>禁用 Maven Nature。
- 删除了项目(但不是磁盘上的内容)。
- 重新导入为Import> General> Existing Project。
- 项目的上下文菜单>配置>转换为Maven项目......。
- 接受来自 Maven 向导的默认值。
- 用备份的 POM 覆盖 POM。(现在你有Maven Dependencies 文件夹)。
- Maven 更新/清理以获得良好的衡量标准。
Hope that helps someone. :)
希望能帮助某人。:)
回答by IceBox13
I had this issue for dependencies that were created in other projects. Downloaded thirdparty dependencies showed up fine in the build path, but not a library that I had created.
对于在其他项目中创建的依赖项,我遇到了这个问题。下载的第三方依赖项在构建路径中显示良好,但不是我创建的库。
SOLUTION:
In the project that is not building correctly,
SOLUTION:
在未正确构建的项目中,
Right-click on the project and choose Properties, and then Maven.
Uncheck the box labeled "Resolve dependencies from Workspace projects"
Hit Apply, and then OK.
Right-click again on your project and do a Maven->Update Snapshots (or Update Dependencies)
右键单击该项目并选择 Properties,然后选择 Maven。
取消勾选框“从工作区项目解决依赖性”
点击应用,然后确定。
再次右键单击您的项目并执行 Maven->Update Snapshots(或更新依赖项)
And your errors should go away when your project rebuilds (automatically if you have auto-build enabled).
当您的项目重建时,您的错误应该会消失(如果您启用了自动构建,则会自动消失)。
回答by Ualter Jr.
Well, I tried everything posted here, unfortunately nothings works in my case. So, trying different combinations I came out with this one that solved my problem.
好吧,我尝试了这里发布的所有内容,不幸的是在我的情况下没有任何效果。所以,尝试不同的组合,我想出了这个解决了我的问题的组合。
1) Open the .classpathfile at the root of your eclipse's project.
1) 打开eclipse项目根目录下的.classpath文件。
2) Insert the following entry to the file:
2) 在文件中插入以下条目:
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
Then, rebuild your project at eclipse (Project->Clean-Build).
然后,在 eclipse 中重建你的项目(Project->Clean-Build)。
回答by FrankDupree
Just in case anybody has tried all the other options and you are still stuck, try right-clicking on the project folder, head over to Maven option and click the "add dependency" button. For some reason Eclipse isn't updating the dependencies manually from the pom.xmlat first try.
以防万一有人尝试了所有其他选项而您仍然卡住,请尝试右键单击项目文件夹,转到 Maven 选项并单击“添加依赖项”按钮。出于某种原因,Eclipse在第一次尝试时不会从pom.xml手动更新依赖项。
回答by Darryl Sibeon
I had a similar problem. I solved it by running the Maven->Update Project Configurationaction
我有一个类似的问题。我通过运行Maven->Update Project Configuration操作解决了这个问题
回答by I. YOCK
For me the problem was maven couldn't find the settings.xmlfile which is located in myMavenFolder\conf.
对我来说,问题是 maven 找不到位于myMavenFolder\conf 中的settings.xml文件。
What I did to fix the issue was to select the right location of the settings.xml file from eclipse:
Window -> Preferences -> Maven -> User Settings
我为解决这个问题所做的是从 eclipse 中选择 settings.xml 文件的正确位置:
Window -> Preferences -> Maven -> User Settings
Finally, hit apply and update your project
最后,点击应用并更新您的项目
回答by Rafael Isquierdo
For the following steps worked in my case:
对于在我的情况下工作的以下步骤:
1On eclipse, right click on the desired project Maven -> Disable Maven Nature
1在 Eclipse 上,右键单击所需的项目Maven -> Disable Maven Nature
2Right click again then go to Properties. Delete every evidence of external Maven dependency leaving only JRE System Library.
2再次右键单击,然后转到“属性”。删除所有外部 Maven 依赖的证据,只留下 JRE 系统库。
3Right click one more time on the project then go to Configure -> Convert to Maven Project
3在项目上再次右键单击一次,然后转到配置 -> 转换为 Maven 项目