eclipse 查找丢失的 Maven 工件

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

Finding missing Maven artifacts

eclipsemavendependencies

提问by matthewb

I'm new to Maven, and struggling with adding dependencies. I'm trying to convert an existing project to Maven, and after adding the dependencies for all the jars in my referenced libraries, I'm receiving an error message about missing artifacts:

我是 Maven 的新手,正在努力添加依赖项。我正在尝试将现有项目转换为 Maven,在为我引用的库中的所有 jar 添加依赖项后,我收到一条关于缺少工件的错误消息:

Missing artifact stax:stax:jar:1.0    
Missing artifact clover:clover:jar:1.3-rc4
Missing artifact log4j:log4j:bundle:1.2.16
Missing artifact stax:stax-ri:jar:1.0

From reading this post: How to handle Maven missing artifact errors?, it sounds like I need to manually download these jars and add them to my local maven repository. My question is how do I find these jars? I tried googling them, and I can find jars that have similar names, but not exactly like these, so I'm not sure if they're the right jars.

从阅读这篇文章:How to handle Maven missing artifact errors? ,听起来我需要手动下载这些 jar 并将它们添加到我的本地 maven 存储库中。我的问题是如何找到这些罐子?我试着用谷歌搜索它们,我可以找到名称相似的罐子,但不完全像这些,所以我不确定它们是否是正确的罐子。

Any tips for dealing with this problem? The log4j jar is the only one explicitly listed in the referenced libraries of my original project, so I'm guessing the other ones are required by other jars that I have, and I don't know where to find them or what their exact names should be.

处理这个问题的任何提示?log4j jar 是我原始项目的引用库中唯一明确列出的 jar,所以我猜我拥有的其他 jar 需要其他 jar,我不知道在哪里可以找到它们或它们的确切名称应该。

Thanks!

谢谢!

回答by matthewb

Thanks to everyone for responding. The actual cause of the problem is that for each of those 3 missing artifacts, for some reason, when Maven downloaded them into my local repository, .lastUpdated was appended to the end of the jar. For example, stax-1.0.jar.lastUpdated. This is the reason Maven could not find stax-1.0.jar.

感谢大家的回应。问题的实际原因是,对于这 3 个缺失的工件中的每一个,出于某种原因,当 Maven 将它们下载到我的本地存储库时, .lastUpdated 被附加到 jar 的末尾。例如,stax-1.0.jar.lastUpdated。这就是 Maven 找不到 stax-1.0.jar 的原因。

So, to fix this problem, I had to manually download stax-1.0.jar, then install it into the local maven repository in the exact same place as the messed up file, so that Maven could find it. (For example, using the command:

所以,为了解决这个问题,我必须手动下载 stax-1.0.jar,然后将它安装到本地 maven 存储库中与混乱文件完全相同的位置,以便 Maven 可以找到它。(例如,使用命令:

mvn install:install-file -Dfile=<path-to-file>/stax-1.0.jar         
-DgroupId=stax -DartifactId=stax -Dversion=1.0 -Dpackaging=jar

Using the same exact groupId and artifactId as the existing, incorrect file was crucial in order for maven to find it.

使用与现有错误文件完全相同的 groupId 和 artifactId 对于 maven 找到它至关重要。

回答by pein-consulting.de

You can find dependency search Sites under maven.apache.org. Go to the left side Navigation Menü entry FAQ (official) and Thun to end of page.

你可以在 maven.apache.org 下找到依赖搜索站点。转到左侧导航菜单条目常见问题解答(官方)和图恩到页面末尾。

回答by Mike McMahon

It's more likely that your POM definition is not correct for log4j. Everything relating to log4j should be readily available in maven.

您的 POM 定义更可能对 log4j 不正确。与 log4j 相关的所有内容都应该在 maven 中随时可用。

Also, if you know the name of the bundle (such as log4j) you can almost always do a quick google search "[bundle name] maven pom"within the first few hits you should either get the maven repo containing a quick snippet on how to include it, or the actual website for the bundled up jar and the maven instructions.

此外,如果您知道包的名称(例如 log4j),您几乎总是可以在前几次点击中进行快速的谷歌搜索“[包名称] maven pom”,您应该获得包含有关如何快速片段的 maven repo包括它,或捆绑 jar 和 maven 说明的实际网站。

For example log4j:

例如 log4j:

<dependencies>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
    </dependency>
</dependencies> 

Sometimes though you just need to specify the repository to find the item in (if it's not hosted in the greater maven repositories)

有时虽然您只需要指定存储库以在其中查找项目(如果它没有托管在更大的 maven 存储库中)

You can specify a new repository like so

您可以像这样指定一个新的存储库

<repositories>
    <repository>
        <id>Java.Net</id>
        <url>http://download.java.net/maven/2/</url>
    </repository>
</repositories>

Finally when you absolutely cannot find the artifact already maven'd up for you (this is usually true for proprietary jars and or drivers that you cannot include with your project) you can have the user manually install the item via command line

最后,当您绝对找不到已经为您准备好的工件时(这通常适用于您不能包含在项目中的专有 jar 和/或驱动程序),您可以让用户通过命令行手动安装该项目

mvn install:install-file -DgroupId=[group-id] -DartifactId=[artifact-id] -Dversion=[version] -Dfile=/path/to/the/file -Dpackaging=[type]

mvn install:install-file -DgroupId=[group-id] -DartifactId=[artifact-id] -Dversion=[version] -Dfile=/path/to/the/file -Dpackaging=[type]

You can then reference it in your maven file using the information described above

然后,您可以使用上述信息在您的 Maven 文件中引用它

For exampleI have a custom reference for a salesforce.com project

例如,我有一个 salesforce.com 项目的自定义参考

mvn install:install-file -DgroupId=com.salesforce -DartifactId=wsc -Dversion=22 -Dfile=\tsclient\H\development\java\wsc-22.jar -Dpackaging=jar

mvn install:install-file -DgroupId=com.salesforce -DartifactId=wsc -Dversion=22 -Dfile=\tsclient\H\development\java\wsc-22.jar -Dpackaging=jar

To access it in maven:

要在 maven 中访问它:

<dependency>
    <groupId>com.salesforce</groupId>
    <artifactId>wsc</artifactId>
    <version>22</version>
</dependency>

Finally, you can find the jars (or their maven info) at their respective websites (please note I'm just basing these links off the jar names, these may not be the actual websites, well sans the log4j which I know to be correct)

最后,您可以在它们各自的网站上找到 jar(或它们的 Maven 信息)(请注意,我只是将这些链接基于 jar 名称,这些可能不是实际的网站,以及我知道正确的 log4j )

Stax

斯塔克斯

Clover

三叶草

Log4j

日志4j

回答by ttn

you can try to add new repositories to your pom.xml

您可以尝试将新的存储库添加到您的 pom.xml

<repositories>
     <repository>
    <id>java.net</id>
    <url>http://download.java.net/maven/2/</url>
    </repository>
      <repository>
        <id>jboss</id>
        <url>http://repository.jboss.com/maven2</url>
 </repository>
</repositories>

回答by Christian

After several days this stupid error bugged me, I found the following article

几天后,这个愚蠢的错误困扰着我,我找到了以下文章

The author describes that there is a workspace repository, which may out of date. In my case it helped just to import the correct plugins again. The workspace repository has been updated and everything is fine.

作者描述有一个工作空间存储库,它可能已过时。就我而言,它有助于再次导入正确的插件。工作区存储库已更新,一切正常。

回答by Kevin Cross

Your problem might be something to do with MNG-4142. This bug means that maven will not download a new snapshot if localCopyis set to truein the artifact maven-metadata-local.xml.

您的问题可能与MNG-4142 有关。这个错误意味着如果在 artifact 中localCopy设置为,maven 将不会下载新的快照。truemaven-metadata-local.xml

Note that the title of this bug is slightly misleading so it is work reading the comments.

请注意,此错误的标题略有误导性,因此请阅读评论。

You might think that using the -Uflag with maven would fix this problem but apparently this is not the case.

您可能认为在-Umaven中使用标志可以解决这个问题,但显然情况并非如此。

The current workaround seems to be searching for all instances of maven-metadata-local.xmland changing the value of localCopyto false.

当前的解决方法似乎是搜索所有实例maven-metadata-local.xml并更改localCopyto的值false

回答by Rohit Deshmukh

I solved this problem by changing the log4jversion from 1.2.15 to 1.2.16.

我通过将log4j版本从 1.2.15更改为 1.2.16解决了这个问题。

回答by darf

It also could be cause by the dom4j. The same error occurred when I use the following settings.

这也可能是由 dom4j 引起的。当我使用以下设置时发生了同样的错误。

<dependency>
    <groupId>dom4j</groupId>
    <artifactId>dom4j</artifactId>
    <version>20040902.021138</version>
</dependency>

After changing to the following, the error disappeared.

改为以下后,错误消失。

<dependency>
    <groupId>dom4j</groupId>
    <artifactId>dom4j</artifactId>
    <version>1.6.1</version>
</dependency>