Java Maven 没有在 Eclipse 中下载依赖项

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

Maven not downloading dependencies in Eclipse

javaeclipsemaven

提问by Ankur Garg

I am setting up a project in eclipse . This projects builds successfully through command line(all mvncommands like mvn package, mvn compile, mvn clean install) work perfectly fine. While setting up this project on STS or Eclipse . I see some of the dependencies are not getting downloaded even though they are present in pom.xml. However, searching them in the maven repository and downloading the jar to my local computer and then adding them to build path makes it work on Eclipse.

我正在 eclipse 中建立一个项目。该项目顺利通过构建命令行(所有的mvn命令一样mvn packagemvn compilemvn clean install)工作完全正常。在 STS 或 Eclipse 上设置此项目时。我看到一些依赖项没有被下载,即使它们存在于pom.xml. 但是,在 maven 存储库中搜索它们并将 jar 下载到我的本地计算机,然后将它们添加到构建路径使其在 Eclipse 上工作。

Is there anything that we need to do to eclipse to make sure it downloads all the dependencies from the repository.

我们需要对 Eclipse 做些什么来确保它从存储库下载所有依赖项。

My POM:

我的POM

<dependency>
    <groupId>org.apache.bookkeeper</groupId>
    <artifactId>bookkeeper-server-compat410</artifactId>
    <version>4.1.0</version>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId>org.apache.bookkeeper</groupId>
            <artifactId>bookkeeper-server</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.apache.bookkeeper</groupId>
    <artifactId>bookkeeper-server-compat420</artifactId>
    <version>4.2.0</version>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId>org.apache.bookkeeper</groupId>
            <artifactId>bookkeeper-server</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Both these artifacts were not downloaded for eclipse and there jars found http://mvnrepository.com/artifact/org.apache.bookkeeper/bookkeeper-server-compat410/4.1.0and http://mvnrepository.com/artifact/org.apache.bookkeeper/bookkeeper-server-compat420/4.2.0were not present in the folder for MavenDependencies and were subsequently giving errors in Eclipse.

这两个工件都没有为 Eclipse 下载,并且在http://mvnrepository.com/artifact/org.apache.bookkeeper/bookkeeper-server-compat410/4.1.0http://mvnrepository.com/artifact/org找到了 jars 。 MavenDependencies文件夹中不存在apache.bookkeeper/bookkeeper-server-compat420/4.2.0,随后在 Eclipse 中出现错误。

enter image description here

在此处输入图片说明

However manually adding them to the build path created a new folder (Reference Library) and resolved the Eclipse Errors . Why did Eclipse not download and import these dependencies by themselves from the maven repository ?? Is it a bug in Eclipse or some problem from my side . Please help.

但是手动将它们添加到构建路径创建了一个新文件夹(参考库)并解决了 Eclipse Errors 。为什么Eclipse不自己从maven仓库下载并导入这些依赖??这是 Eclipse 中的错误还是我这边的一些问题。请帮忙。

enter image description here

在此处输入图片说明

采纳答案by VdeX

Solution 1:

解决方案1:

Set correct proxy:

设置正确的代理:

<proxy>
    <id>optional</id>
    <active>false</active>
    <protocol>http</protocol>
    <username></username>
    <password></password>
    <host>172.27.171.91</host>
    <port>8080</port>
</proxy>

Solution2 :

解决方案2:

just delete

只是删除

lastupdated extension files from folder

and try updating maven.

并尝试更新 maven。

[Most of the times this solution will work]

[大多数情况下此解决方案会起作用]

回答by Saket Mittal

I got the same problem and this is how i solved. :

我遇到了同样的问题,这就是我解决的方法。:

  1. Right click your project, choose Run As -> Maven install. Observe the output console to see the installation progress. After the installation is finished, you can continue to the next step.
  1. 右键单击您的项目,选择 Run As -> Maven install。观察输出控制台以查看安装进度。安装完成后,您可以继续下一步。

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

  1. Right click your Spring MVC project, choose Maven -> Update Project.
  1. 右键单击您的 Spring MVC 项目,选择 Maven -> 更新项目。

enter image description here

在此处输入图片说明

  1. Choose your project and click OK. Wait until update process is finished.
  2. The error still yet, then do Project->Clean and then be sure you have selected our project directory and then do the follow Project->Build.
  1. 选择您的项目并单击确定。等待更新过程完成。
  2. 错误仍然存​​在,然后执行 Project->Clean 并确保您选择了我们的项目目录,然后执行以下 Project->Build。

回答by CKM

In my case, I had unchecked Build automatically. Checking it again started downloading the jars.

就我而言,我没有选中Build automatically. 再次检查它开始下载罐子。

回答by SachinB

I was facing similar sort of issue. I tried deleting folders inside .m2 and again building maven project.
I could download all dependency except one dependency which we have created by ourselves and published on Nexus.
Then I changed by java pointing from JRE to JDK which solved my problem

我面临着类似的问题。我尝试删除 .m2 中的文件夹,然后再次构建 maven 项目。
除了我们自己创建并在 Nexus 上发布的一个依赖项之外,我可以下载所有依赖项。
然后我通过 java 从 JRE 指向 JDK 解决了我的问题

回答by vinayrao

The following worked for me.
Just right-click on Project -> Maven -> Update Project...such as it is shown here.

以下对我有用。
在只需右键单击Project -> Maven -> Update Project...如所示。它在这里

回答by Snozzlebert

Sometimes there is an error downloading a dependency - eg. some files are downloaded but the actual JAR is missing from the local Maven repository.

有时下载依赖项时会出错 - 例如。下载了一些文件,但本地 Maven 存储库中缺少实际的 JAR。

In this case I had to delete the whole folder of the problematic dependency in the local maven repository. Only then did Maven update work (Right-click on the project and select Project > Maven > Update Project.... ) enter image description hereenter image description here

在这种情况下,我不得不删除本地 maven 存储库中存在问题的依赖项的整个文件夹。只有这样 Maven 更新工作(右键单击项目并选择Project > Maven > Update Project.... ) 在此处输入图片说明在此处输入图片说明

回答by PAQuality101

I had faced a similar issue and following the below steps helped me fix it.

我遇到了类似的问题,按照以下步骤帮助我解决了这个问题。

  1. Delete the last modified jar from respective folders.
  2. Select the project

    • Right Click -> Maven

    • Update project..

  1. 从相应的文件夹中删除最后修改的 jar。
  2. 选择项目

    • 右键单击-> Maven

    • 更新项目..

It will download all the missing Jars.

它将下载所有丢失的罐子。

回答by Sumanth Varada

I have come across the same issue recently.

我最近遇到了同样的问题。

First of all you have to configure proxy settings in settings.xml in your maven repository.

首先,您必须在 Maven 存储库的 settings.xml 中配置代理设置。

If you are using eclipse/STS then please do verify following.

如果您使用的是 eclipse/STS,请验证以下内容。

Window -> Preferences -> Maven -> User Settings -> update user settings by pointing your settings.xml

Now it's set to update the maven project. It worked for me.

现在它设置为更新 Maven 项目。它对我有用。

回答by Shubham Pandey

For me I changed the packaging from pom to jar, and then the dependency got downloaded.

对我来说,我将包装从 pom 更改为 jar,然后下载了依赖项。

so I changed from <packaging>pom</packaging> to <packaging>jar</packaging>

回答by Ankush kumar

  1. Try to move your dependencies from "type" tag to "scope" tag like below
  1. 尝试将您的依赖项从“类型”标签移动到“范围”标签,如下所示

or

或者

<dependency>
        <groupId>net.xyz.xyz</groupId>
        <artifactId>xyz-xyz</artifactId>
        <version>x.y.z</version>
        <type>pom</type>
 </dependency>

or

或者

<dependency>
            <groupId>net.xyz.xyz</groupId>
            <artifactId>xyz-xyz</artifactId>
            <version>x.y.z</version>
            <scope>test</scope> 
     </dependency>

then further Maven > Update Project

然后进一步 Maven > 更新项目