Java 如何修复 Eclipse 中的 Maven、Maven 配置和 Maven 依赖问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22481931/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 16:00:28  来源:igfitidea点击:

How to fix Maven, Maven Configuration and Maven Dependency Problems in Eclipse

javaeclipsemaven

提问by ruhungry

Edit:I have not resolved this problem yet but this post could be really useful in this kind of problems:

编辑:我还没有解决这个问题,但这篇文章可能对这类问题非常有用:

How to fix your Maven problems

如何解决您的 Maven 问题



I did svn checkoutof my maven project to directory MainDirectory. Everything went well.

我将我的 Maven 项目svn checkout到目录 MainDirectory。一切顺利。

Next, I went to MainDirectory and I run command

接下来,我转到 MainDirectory 并运行命令

mvn clean package

mvn 清洁包

with BUILD SUCCESS

建立成功

I went to directory of my project MainDirectory/MyProject and I run the same command, once again it worked well.

我转到我的项目 MainDirectory/MyProject 的目录并运行相同的命令,它再次运行良好。

I run Eclipse and I wanted to import "Existing Maven Projects". I chose MainDirectory as RootDirectory and I got a warning:

我运行 Eclipse,我想导入“现有的 Maven 项目”。我选择 MainDirectory 作为 RootDirectory 并收到警告:

Warning

警告

I clicked next and I saw few errors:

我点击了下一步,我看到了一些错误:

Errors

错误

Anyhow, I clicked finish (because of Action: Resolve Later)

无论如何,我点击了完成(因为操作:稍后解决

I was waiting few seconds and I saw this error:

我等了几秒钟,我看到了这个错误:

Error2

错误 2

but my projects are visible in Project Explorer.

但我的项目在项目资源管理器中可见。

I was carrying on. I imported second "Existing Maven Projects" - MainDirectory/MyProject. This time, I had no warning. I clicked next and errors appeared:

我在继续。我导入了第二个“现有 Maven 项目” - MainDirectory/MyProject。这一次,我没有任何警告。我点击下一步并出现错误:

Error3

错误 3

I clicked finish and another error appeared:

我点击完成并出现另一个错误:

Error4

错误 4

Anyhow, new project exists now in Project Explorer.

无论如何,新项目现在存在于 Project Explorer 中。

I went to Project->Cleanand I chose all my projects. Once again I got an error:

我去了Project->Clean并选择了我所有的项目。我再次遇到错误:

Error5

错误 5

Finally, I tried Maven->Update Projectand another error appeared:

最后,我尝试了Maven->Update Project并且出现了另一个错误:

Error6

错误 6

I was trying to clean somehow my local repo but I am not sure if I did it correctly.

我试图以某种方式清理我的本地仓库,但我不确定我是否做得正确。

Finally in Eclipse I see errors as below:

最后在 Eclipse 中,我看到如下错误:

enter image description here

在此处输入图片说明

In fact, I have already done this procedure once few days ago and everything worked perfectly.

事实上,我几天前已经做过一次这个程序,一切都很完美。

When I run my application:

当我运行我的应用程序时:

mvn jetty:run

It works perfectly.

它完美地工作。

Thank you in advance

先感谢您

采纳答案by Mithun Khatri

I have already got this problem, please make sure that the configuration file path of maven is correctly set in your eclipse ? If you install maven by yourself it is setting with a default path which might not be the same as yours.

我已经遇到这个问题了,请问你的eclipse中maven的配置文件路径设置是否正确?如果你自己安装 maven,它设置的默认路径可能与你的不同。

Check the following screen to check if you have the good settings, to go here just go to window->preferenceand type maven in the type filter :

检查以下屏幕以检查您是否有良好的设置,只需转到window->preference并在类型过滤器中键入 maven 即可:

Maven Setting

Maven 设置

回答by djmorton

Another Stackoverflow user was having a similar problem and there are several things to try listed as answers to that question. Do any of the workarounds outlined on that question help you?

另一个 Stackoverflow 用户也遇到了类似的问题,有几件事可以尝试作为该问题的答案。该问题中概述的任何解决方法对您有帮助吗?

Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved

无法计算构建计划:插件 org.apache.maven.plugins:maven-resources-plugin:2.5 或其依赖项之一无法解析

回答by Mithun Khatri

There may be following solutions-

可能有以下解决方案——

  1. Convert project into maven project(if maven nature is not there in project configuration)
  2. Check Maven Dependency Library in Build Path. None of the dependency should throw error.
  1. 将项目转换为 maven 项目(如果项目配置中没有 maven 性质)
  2. 在构建路径中检查 Maven 依赖库。任何依赖项都不应该抛出错误。

If problem still persist then-

如果问题仍然存在那么-

  1. Open terminal, goto the project folder where pom.xml is present and run mvn eclipse:eclipsecommand in terminal and refresh the project in eclipse.

  2. run mvn clean installto install jar in local repo(.m2) (run mvn clean install -Dmaven.test.skip=trueif you want to skip test cases.)

  1. 打开终端,转到存在 pom.xml 的项目文件夹并mvn eclipse:eclipse在终端中运行命令并在 eclipse 中刷新项目。

  2. 运行mvn clean install以在本地 repo(.m2) 中安装 jar(mvn clean install -Dmaven.test.skip=true如果您想跳过测试用例,请运行。)

It should definitely work.

它绝对应该工作。

回答by Pratik Kasalkar

I had the same issue. I changed the apache maven plugin version in pom.xmlto the version used by the web-app in web.xml. Then Maven > Update Project.

我遇到过同样的问题。我将pom.xml 中的 apache maven 插件版本更改为web.xml 中web-app 使用的版本。然后 Maven > 更新项目。

Note: The jdk/jre should be compatible to plugins you are using.

注意:jdk/jre 应该与您正在使用的插件兼容。