m2eclipse 未找到 Maven 依赖项,未找到工件

发布于 2024-08-24 02:34:50 字数 1418 浏览 5 评论 0原文

我使用 m2eclipse 作为 eclipse 的 Maven 2 插件。我是 Maven 的新手,所以我的错误可能很简单,尽管搜索没有为我提供任何解决方案。我可以从命令行运行 Maven 并且它构建成功。但是,如果我导入为现有的 Maven 项目,或者使用 mvn eclipse:eclipse 然后导入,我会得到在我的 POM 文件中找不到的工件,导致根本没有加载 Maven 依赖项。

奇怪的是我有 2 个项目,两个项目都是父 pom 打包项目的子项目。一个孩子加载了我所有的 Maven 依赖项,而另一个孩子找不到任何依赖项,并说我的 pom 文件缺少工件。同样,我可以从命令行很好地安装和打包它们。

我什至尝试将我的项目加载到运行完美的netbeans中,但是我需要使用eclipse。

关于如何解决这个问题有什么想法吗?

更新

目录结构、pom 文件布局:

--main
  --pom.xml   (is a pom package that is the parent to two other projects)
  --ProjectA
    --pom.xml
  --ProjectB
    --pom.xml

Main 是 ProjectA 和 ProjectB 的父项目。 ProjectB 将 ProjectA 作为依赖项。显然 m2eclipse 对这种依赖性并不满意。一旦我从ProjectB的pom文件中删除ProjectA的依赖项,所有maven依赖项都会被eclipse找到。

- 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)

但是,我仍然需要 ProjectB 才能具有 ProjectA 的依赖关系。错误消息似乎是 m2eclipse 在远程存储库中查找 ProjectA。项目 A 应该只位于 .m2 目录中,但我不确定如何告诉 m2eclipse 在那里查看。

我认为这可能只是 m2eclipse 的特定问题,因为从命令行使用 mvn 工作正常,并且就像我之前所说的那样,netbeans 加载项目和依赖项也很好。

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.

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.

I even tried loading my projects into netbeans which worked flawlessly, however I am required to use eclipse.

Any ideas on how to fix this?

Update

Directory structure, pom files layout:

--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.

- 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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

小帐篷 2024-08-31 02:34:51

听起来您的 m2eclipse 安装正在使用嵌入式 Maven,它有自己的存储库(位于用户主目录下)和设置。

如果您打开 Maven 首选项(窗口->首选项->Maven->安装,您可以通过选择 添加... 添加 Maven 安装,然后浏览到 M2_HOME 目录

首选项屏幕截图
(来源:sonatype.com)

有关更多详细信息,请参阅 m2eclipse 书

It sounds like your m2eclipse install is using the embedded Maven, which has its own repository (located under user home) and settings.

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.

Preferences screenshot
(source: sonatype.com)

For more details see the m2eclipse book

习惯成性 2024-08-31 02:34:51

对我来说,maven 正在下载依赖项,但无法将其添加到类路径中。我看到了项目的.classpath,它没有任何与maven相关的条目。当我添加时,

<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>

问题已为我解决。

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

<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>

the issue got resolved for me.

熟人话多 2024-08-31 02:34:51

我发现的原因之一是它在存储库中找不到 jar 的原因可能是因为该特定 jar 的 .pom 文件可能丢失或损坏。只需更正它并尝试从本地存储库加载即可。

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.

蓝咒 2024-08-31 02:34:51

好吧,我解决了这个问题。必须首先将项目转换为 Maven 项目,然后从 Eclipse 工作区中删除它们,然后重新导入它们。

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.

草莓味的萝莉 2024-08-31 02:34:51

我在使用 m2eclipse 时遇到问题(即它似乎根本没有安装),但我使用 IAM 开发一个项目 - 由 Eclipse 基金会(或托管或类似的东西)支持的 eclipse 的 maven 插件。

我有时会遇到问题,因为有时项目会出现一些奇怪的错误(它无法移动某些东西),但简单的命令(从 Eclipse 作为任务或从控制台运行)+刷新(F5)解决了所有问题:

mvn clean

但是请注意,我在 eclipse 中创建了项目。不过我手动修改了 pom.xml

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).

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:

mvn clean

However please note that I created project in eclipse. However I modified pom.xml by hand.

水中月 2024-08-31 02:34:51

如果您使用自定义“Settings.xml”,并在其中配置了不同的 ,这可能会出现问题。

Eclipse 将使用 MAVEN 的默认安装,并将使用用户的默认位置来查找本地 Maven 存储库,在 Linux 系统上该位置为“/home/${USER}/.m2/”

Eclipse 可以通过执行以下操作,可以轻松配置为使用自定义的“Settings.xml”:
转到->窗口->首选项->选择“Maven”->选择“用户设置”

  1. 在“用户设置”下,选择自定义“Settings.xml”文件,对于“用户设置”,单击“浏览”并选择自定义“Settings.xml”。
  2. 单击“更新设置”,如果“本地存储库”文本框未显示上述文件中的自定义位置,只需键入该位置并单击“重新索引”。
  3. 单击“确定”

之后,您可以继续从“项目资源管理器”中选择您的项目,右键单击,选择“Maven”> “更新项目”。确保在窗口中选择(勾选)您的项目,然后单击“确定”。

如果使用 Maven 的自定义“Settings.xml”,这应该有助于解决问题。

希望有帮助。

This could be a problem if you are using a custom 'Settings.xml', with a different <localRepository> configured in it.

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 can be easily configured to use the customized 'Settings.xml', by doing the following:
Goto -> Window -> Preferences -> Select 'Maven' -> Select 'User Settings'

  1. Under 'User Settings', select the custom 'Settings.xml' file, for 'User Settings' by clicking 'Browse' and selecting the customized 'Settings.xml'.
  2. 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'.
  3. Click 'OK'

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'.

This should help to resolve the issue, if using custom 'Settings.xml' for Maven.

Hope it helps.

羁客 2024-08-31 02:34:50

我在其他项目中创建的依赖项遇到了这个问题。下载的第三方依赖项在构建路径中显示良好,但不是我创建的库。

解决方案:在未正确构建的项目中,右键单击该项目并选择“属性”,然后选择“Maven”。取消选中标有“解决工作区项目的依赖关系”的框,单击“应用”,然后单击“确定”。再次右键单击您的项目并执行 Maven-> 更新快照(或更新依赖项),当您的项目重建时,您的错误应该会消失(如果您启用了自动构建,则会自动消失)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文