Java maven- 不在 pom.xml 文件中下载新添加的依赖项

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

maven- not downloading new added dependency in pom.xml file

javamaven

提问by S Singh

I need new third party jar for reading csv in maven based project. So, I did entry in pom.xml for same as below.

我需要新的第三方 jar 来读取基于 maven 的项目中的 csv。所以,我在 pom.xml 中输入了与下面相同的内容。

<dependency>
        <groupId>net.sf.opencsv</groupId>
        <artifactId>opencsv</artifactId>
        <version>2.0</version>
    </dependency>

But when I run mvn install or mvn package command, It does not download newly added dependency and just build project and generate war.

但是当我运行 mvn install 或 mvn package 命令时,它不会下载新添加的依赖项而只是构建项目并生成战争。

I am trying to get the issue! Please share solution if anybody face this earlier!

我正在努力解决这个问题!如果有人早点遇到这个问题,请分享解决方案!

Regards

问候

采纳答案by S Singh

I resolved this issue by following steps:

我通过以下步骤解决了这个问题:

1). Remove concerned jar from local /m2 folder. 2). Run mvn eclipse:eclipsecommand 3). And last run: mvn clean install

1)。从本地 /m2 文件夹中删除相关 jar。2)。运行mvn eclipse:eclipse命令 3)。最后运行:mvn clean install

Now I am looking for concerned jar in my project class path!

现在我正在我的项目类路径中寻找相关的 jar!

回答by Dónal Boyle

Try running a forced update:

尝试运行强制更新:

mvn clean install -U

The -U (uppercase U) forces maven to look at all dependencies and try to update them.

-U(大写 U)强制 maven 查看所有依赖项并尝试更新它们。

回答by Lucas Tadeu

Try:

尝试:

Menu -> Project -> Clean -> Select the project

菜单 -> 项目 -> 清理 -> 选择项目

Right Click on the project -> Maven -> Maven clean

右键单击项目 -> Maven -> Maven clean

Right Click on the project -> Maven -> Maven install

右键单击项目 -> Maven -> Maven install

Happened to me and it has fixed my problem. Hope it helps you.

发生在我身上,它解决了我的问题。希望对你有帮助。

回答by PriyaJames

I deleted .m2 folder and then from eclipse ran maven install then took maven update project. It resolved my issue and jar file got downloaded.

我删除了 .m2 文件夹,然后从 eclipse 运行 maven install 然后进行 maven update 项目。它解决了我的问题,并下载了 jar 文件。

回答by AndrewSantosa

If the dependency is defined in a <dependencies>block that is within a <dependencyManagement>block, adding it without the version number to a <dependencies>block that is outside <dependencyManagement>may fix the problem.

如果依赖项是在<dependencies>块内的<dependencyManagement>块中定义的,则将不带版本号的它添加到<dependencies>外部块中<dependencyManagement>可能会解决问题。

This is because the purpose of <dependencyManagement>block is to manage dependency versions, and not to install the dependencies. See this other article: Differences between dependencyManagement and dependencies in Maven

这是因为<dependencyManagement>block的目的是管理依赖版本,而不是安装依赖。请参阅另一篇文章:Maven 中dependencyManagement 和dependencies 之间的差异