eclipse m2eclipse 未找到 maven 依赖项,未找到工件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2393685/
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
m2eclipse not finding maven dependencies, artifacts not found
提问by vagabond
I'm using m2eclipse as my maven 2 plugin for eclipse. I'm brand new to maven, so my mistake might be simple, although searching has not yielded any solutions for me. I can run maven from the command line and it build successfully. However if I import as an existing maven project, or use mvn eclipse:eclipse and then import I get the artifacts not found in my POM file resulting in no maven dependencies being loaded at all.
我使用 m2eclipse 作为我的 Eclipse 的 Maven 2 插件。我是 maven 的新手,所以我的错误可能很简单,尽管搜索并没有为我找到任何解决方案。我可以从命令行运行 maven 并成功构建。但是,如果我作为现有的 maven 项目导入,或者使用 mvn eclipse:eclipse 然后导入,我会在 POM 文件中找不到工件,导致根本没有加载 maven 依赖项。
What's odd is that I have 2 projects, both children to a parent pom packaged project. One child loads all my maven dependencies while the other cannot find any and says my pom file is missing artifacts. Again, I can install and package them all just fine from the command line.
奇怪的是我有 2 个项目,两个孩子都是一个父 pom 打包项目。一个孩子加载了我所有的 maven 依赖项,而另一个孩子找不到任何依赖项,并说我的 pom 文件缺少工件。同样,我可以从命令行很好地安装和打包它们。
I even tried loading my projects into netbeans which worked flawlessly, however I am required to use eclipse.
我什至尝试将我的项目加载到运行完美的 netbeans 中,但是我需要使用 eclipse。
Any ideas on how to fix this?
有想法该怎么解决这个吗?
Update
更新
Directory structure, pom files layout:
目录结构,pom文件布局:
--main
--pom.xml (is a pom package that is the parent to two other projects)
--ProjectA
--pom.xml
--ProjectB
--pom.xml
Main is the parent project of both ProjectA and ProjectB. ProjectB has ProjectA as a dependency. Apprently m2eclipse is not happy about that depedency. As soon as I remove the dependency of ProjectA from ProjectB's pom file all the maven dependencies are found by eclipse.
Main 是 ProjectA 和 ProjectB 的父项目。ProjectB 将 ProjectA 作为依赖项。显然,m2eclipse 对这种依赖性并不满意。一旦我从 ProjectB 的 pom 文件中删除了 ProjectA 的依赖项,eclipse 就会找到所有 maven 依赖项。
- com.company.myproj:app:6.6.0:jar Missing: ---------- 1) com.company.myproj:main:pom:${myproj.version} ---------- 1 required artifact is missing. for artifact: com.company.myproj:main:pom:$
{myproj.version} from the specified remote repositories: apache-incubating (http://people.apache.org/repo/m2-incubating-repository/, releases=true, snapshots=true), central (http://
repo1.maven.org/maven2, releases=true, snapshots=false)
However, I still need ProjectB to have that dependency for ProjectA. The error message seems to be m2eclipse looking for ProjectA in a remote repo. Project A should only be in .m2 directory, but I'm not sure how to tell m2eclipse to look there.
但是,我仍然需要 ProjectB 才能对 ProjectA 产生依赖。错误消息似乎是 m2eclipse 在远程存储库中寻找 ProjectA。项目 A 应该只在 .m2 目录中,但我不确定如何告诉 m2eclipse 在那里查看。
I think this may be just a m2eclipse specific issue because using mvn from the command line works fine and like I said previously, netbeans loads the projects and dependencies just fine.
我认为这可能只是 m2eclipse 特定的问题,因为从命令行使用 mvn 工作正常,就像我之前说的那样,netbeans 加载项目和依赖项就好了。
回答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, 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) and your errors should go away when your project rebuilds (automatically if you have auto-build enabled).
SOLUTION: 在未正确构建的项目中,右键单击该项目并选择 Properties,然后选择 Maven。取消选中标有“解决工作区项目的依赖关系”的框,点击应用,然后点击确定。再次右键单击您的项目并执行 Maven->Update Snapshots(或更新依赖项),当您的项目重建时,您的错误应该会消失(如果您启用了自动构建,则会自动消失)。
回答by Rich Seller
It sounds like your m2eclipse install is using the embedded Maven, which has its own repository (located under user home) and settings.
听起来您的 m2eclipse 安装使用的是嵌入式 Maven,它有自己的存储库(位于用户主目录下)和设置。
If you open up the Maven preferences (Window->Preferences->Maven->Installations, you can add your Maven installation by selecting Add...then browsing to the M2_HOME directory.
如果您打开 Maven 首选项(Window-> Preferences-> Maven-> Installations,您可以通过选择Add...然后浏览到 M2_HOME 目录来添加您的 Maven 安装。
(source: sonatype.com)
(来源:sonatype.com)
For more details see the m2eclipse book
有关更多详细信息,请参阅m2eclipse 书
回答by Harshal Waghmare
For me maven was downloading the dependency but was unable to add it to the classpath. I saw my .classpath of the project,it didnt have any maven-related entry. When I added
对我来说,maven 正在下载依赖项,但无法将其添加到类路径中。我看到了我的项目的 .classpath,它没有任何与 maven 相关的条目。当我添加
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
the issue got resolved for me.
问题为我解决了。
回答by HP24
One of the reason I found was why it doesn't find a jar from repository might be because the .pom file for that particular jar might be missing or corrupt. Just correct it and try to load from local repository.
我发现的原因之一是为什么它没有从存储库中找到 jar 可能是因为该特定 jar 的 .pom 文件可能丢失或损坏。只需更正它并尝试从本地存储库加载。
回答by Steven L
Okay I fixed this thing. Had to first convert the projects to Maven Projects, then remove them from the Eclipse workspace, and then re-import them.
好的,我解决了这个问题。必须首先将项目转换为 Maven 项目,然后将它们从 Eclipse 工作区中删除,然后重新导入它们。
回答by Maciej Piechotka
I had problems with using m2eclipse (i.e. it did not appear to be installed at all) but I develop a project using IAM- maven plugin for eclipse supported by Eclipse Foundation (or hosted or something like that).
我在使用 m2eclipse 时遇到了问题(即它似乎根本没有安装),但我使用IAM开发了一个项目- Eclipse Foundation(或托管或类似的东西)支持的 Eclipse 的 maven 插件。
I had sometimes problems as sometimes some strange error appeared for project (it couldn't move something) but simple command (run from eclipse as task or from console) + refresh (F5
) solved all problems:
我有时会遇到问题,因为有时项目会出现一些奇怪的错误(它无法移动某些东西)但是简单的命令(从 eclipse 作为任务或从控制台运行)+ refresh ( F5
) 解决了所有问题:
mvn clean
However please note that I created project in eclipse. However I modified pom.xml
by hand.
但是请注意,我在 eclipse 中创建了项目。不过我pom.xml
是手动修改的。
回答by Dinesh Kumar
This could be a problem if you are using a custom 'Settings.xml', with a different <localRepository>
configured in it.
如果您使用自定义的“Settings.xml”,其中<localRepository>
配置了不同的内容,这可能会成为一个问题。
Eclipse will be using the default installation of MAVEN, and will be using the default location for the User to look for the local Maven repository, which on Linux systems would be '/home/${USER}/.m2/'
Eclipse 将使用 MAVEN 的默认安装,并将使用用户的默认位置来查找本地 Maven 存储库,在 Linux 系统上为“/home/${USER}/.m2/”
Eclipse can be easily configured to use the customized 'Settings.xml', by doing the following: Goto -> Window -> Preferences -> Select 'Maven' -> Select 'User Settings'
通过执行以下操作,可以轻松地将 Eclipse 配置为使用自定义的“Settings.xml”:转到 -> 窗口 -> 首选项 -> 选择“Maven” -> 选择“用户设置”
- Under 'User Settings', select the custom 'Settings.xml' file, for 'User Settings' by clicking 'Browse' and selecting the customized 'Settings.xml'.
- Click on 'Update Settings', if the 'Local Repository' Textbox does not show the custom location from the file above, just key in the location and click 'Reindex'.
- Click 'OK'
- 在“用户设置”下,通过单击“浏览”并选择自定义的“Settings.xml”为“用户设置”选择自定义的“Settings.xml”文件。
- 单击“更新设置”,如果“本地存储库”文本框未显示上述文件中的自定义位置,只需键入该位置并单击“重新索引”。
- 点击“确定”
After this, you could proceed to select your project from the 'Project Explorer', right click, Select 'Maven' > 'Update Project'. Make sure that your project is selected (ticked) in the Window, and click 'OK'.
在此之后,您可以继续从“项目资源管理器”中选择您的项目,右键单击,选择“Maven”>“更新项目”。确保在窗口中选择(勾选)您的项目,然后单击“确定”。
This should help to resolve the issue, if using custom 'Settings.xml' for Maven.
如果为 Maven 使用自定义“Settings.xml”,这应该有助于解决问题。
Hope it helps.
希望能帮助到你。