简体   繁体   English

Maven 没有在 Eclipse 中下载依赖项

[英]Maven not downloading dependencies in Eclipse

I am setting up a project in eclipse .我正在 eclipse 中建立一个项目。 This projects builds successfully through command line(all mvn commands like mvn package , mvn compile , mvn clean install ) work perfectly fine.这个项目通过命令行成功构建(所有mvn命令,如mvn packagemvn compilemvn clean install )工作得很好。 While setting up this project on STS or Eclipse .在 STS 或 Eclipse 上设置此项目时。 I see some of the dependencies are not getting downloaded even though they are present in pom.xml .我看到一些依赖项没有被下载,即使它们存在于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.但是,在 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.0 and http://mvnrepository.com/artifact/org.apache.bookkeeper/bookkeeper-server-compat420/4.2.0 were 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 中出现错误。

在此处输入图片说明

However manually adding them to the build path created a new folder (Reference Library) and resolved the Eclipse Errors .但是手动将它们添加到构建路径创建了一个新文件夹(参考库)并解决了 Eclipse Errors 。 Why did Eclipse not download and import these dependencies by themselves from the maven repository ??为什么Eclipse不自己从maven仓库下载并导入这些依赖?? Is it a bug in Eclipse or some problem from my side .这是 Eclipse 中的错误还是我这边的一些问题。 Please help.请帮忙。

在此处输入图片说明

I got the same problem and this is how i solved.我遇到了同样的问题,这就是我解决的方法。 :

  1. Right click your project, choose Run As -> Maven install.右键单击您的项目,选择 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. Right click your Spring MVC project, choose Maven -> Update Project.右键单击您的 Spring MVC 项目,选择 Maven -> 更新项目。

在此处输入图片说明

  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.错误仍然存​​在,然后执行 Project->Clean 并确保您选择了我们的项目目录,然后执行以下 Project->Build。

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] [大多数情况下此解决方案会起作用]

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 .在这种情况下,我不得不删除本地 maven 存储库中存在问题的依赖项的整个文件夹 Only then did Maven update work (Right-click on the project and select Project > Maven > Update Project... . )只有这样 Maven 更新工作(右键单击项目并选择Project > Maven > Update Project... . ) 在此处输入图片说明 在此处输入图片说明

In my case, I had unchecked Build automatically .就我而言,我没有选中Build automatically Checking it again started downloading the jars.再次检查它开始下载罐子。

I was facing similar sort of issue.我面临着类似的问题。 I tried deleting folders inside .m2 and again building maven project.我尝试删除 .m2 中的文件夹并再次构建 maven 项目。
I could download all dependency except one dependency which we have created by ourselves and published on Nexus.除了我们自己创建并在 Nexus 上发布的一个依赖项之外,我可以下载所有依赖项。
Then I changed by java pointing from JRE to JDK which solved my problem然后我通过 java 从 JRE 指向 JDK 解决了我的问题

The following worked for me.以下对我有用。
Just right-click on Project -> Maven -> Update Project... such as it is shown here .在只需右键单击Project -> Maven -> Update Project...如它显示在这里

I had faced a similar issue and following the below steps helped me fix it.我遇到了类似的问题,按照以下步骤帮助我解决了这个问题。

  1. Delete the last modified jar from respective folders.从相应的文件夹中删除最后修改的 jar。
  2. Select the project选择项目

    • Right Click -> Maven右键单击-> Maven

    • Update project..更新项目..

It will download all the missing Jars.它将下载所有丢失的罐子。

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.现在它设置为更新 Maven 项目。 It worked for me.它对我有用。

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

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

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 > 更新项目

Make sure you're defining the dependency as close as possible to the leaf of the project tree where it is needed.确保您定义的依赖关系尽可能靠近需要它的项目树的叶子。 Otherwise, Maven might ignore it.否则,Maven 可能会忽略它。

For example, if you have a parent project that references projects A and B and the dependency is with respect to project A, then defining the dependency in the parent's pom.xml might get ignored by Maven.例如,如果您有一个引用项目 A 和 B 的父项目,并且依赖项是关于项目 A 的,那么在父项的 pom.xml 中定义依赖项可能会被 Maven 忽略。 So, define it in project A's pom.xml.因此,在项目 A 的 pom.xml 中定义它。

Parent Project's pom.xml
   Sub-project A's pom.xml <<< define the dependency where it is needed
   Sub-project B's pom.xml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM