在中央仓库(http://repo1.maven.org/maven2)中找不到资源。

8

通常情况下,我该如何解决Maven仓库中的资源未找到问题?是否有其他可添加到pom.xml文件的仓库列表?我尝试了命令行中列出的解决方案,但它并没有生效,尽管Maven报告它为成功。

I tried to build test-analytics, but got error:

[INFO]    task-segment: [install]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 6 resources
Downloading: http://repo1.maven.org/maven2/com/google/code/gwt-dnd/gwt-dnd/3.1.1/gwt-dnd-3.1.1.pom
[INFO] Unable to find resource 'com.google.code.gwt-dnd:gwt-dnd:pom:3.1.1' in repository central (http://repo1.maven.org/maven2)
Downloading: http://repo1.maven.org/maven2/com/google/code/gwt-dnd/gwt-dnd/3.1.1/gwt-dnd-3.1.1.jar
[INFO] Unable to find resource 'com.google.code.gwt-dnd:gwt-dnd:jar:3.1.1' in repository central (http://repo1.maven.org/maven2)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.

Missing:
----------
1) com.google.code.gwt-dnd:gwt-dnd:jar:3.1.1

  Try downloading the file manually from the project website.

  Then, install it using the command: 
      mvn install:install-file -DgroupId=com.google.code.gwt-dnd -DartifactId=gwt-dnd -Dversion=3.1.1 -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there: 
      mvn deploy:deploy-file -DgroupId=com.google.code.gwt-dnd -DartifactId=gwt-dnd -Dversion=3.1.1 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency: 
    1) com.google.testing.testify.risk.frontend:test-analytics:war:1.0-SNAPSHOT
    2) com.google.code.gwt-dnd:gwt-dnd:jar:3.1.1

----------
1 required artifact is missing.

for artifact: 
  com.google.testing.testify.risk.frontend:test-analytics:war:1.0-SNAPSHOT

from the specified remote repositories:
  central (http://repo1.maven.org/maven2)



[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Sun Nov 18 21:24:23 EST 2012
[INFO] Final Memory: 16M/238M
[INFO] ------------------------------------------------------------------------

以下是命令和错误信息:

 mvn deploy:deploy-file -DgroupId=com.google.code.gwt-dnd -DartifactId=gwt-dnd -Dversion=3.1.1 -Dpackaging=jar -Dfile=gwt-dnd-3.1.1.jar
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'deploy'.
[INFO] ------------------------------------------------------------------------
[INFO] Building test-analytics
[INFO]    task-segment: [deploy:deploy-file] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] One or more required plugin parameters are invalid/missing for 'deploy:deploy-file'

[0] Inside the definition for plugin 'maven-deploy-plugin' specify the following:

<configuration>
  ...
  <url>VALUE</url>
</configuration>

-OR-

on the command line, specify: '-Durl=VALUE'

[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Tue Nov 20 14:10:37 EST 2012
[INFO] Final Memory: 14M/238M
[INFO] ------------------------------------------------------------------------
2个回答

17
您缺乏有关Maven世界的一些基本理解。因此,以下是有关存储库的简要概述,可以帮助您。
首先,在运行maven“开箱即用”时,有两个可用的存储库,这就是您所做的。您有1)Maven Central和2)本地repo,即〜/ .m2 / repository。本地库是一种缓存,您本地构建的工件将通过“mvn install”命令“安装”到其中。请注意,“mvn deploy”命令“部署”工件,这类似于安装,但它意味着将工件放入“远程存储库”。Maven Central是一个远程存储库,所有存储库(除了单个本地存储库)都是远程存储库,但您不能随意发布到它。它用于审核过的,发布质量的工件。
因此,您的构建找不到Google工件。这意味着它们不在Maven Central中,尽管您可以检查。http://search.maven.org/ 如果它们不在那里,您有几个选项。
1)在本地repo中“安装”工件(这应该是您的第一步,因为它非常轻便)
2)运行自己的存储库服务器,例如Nexus。这是您自己的“远程存储库”,并且您可以将Google工件“部署”到其中。
3)找出Google工件是否在另一个公开可用的远程存储库中--有几个重要的存储库不在开箱即用的Maven存储库定义中,但您可以添加它们。
请注意,这三个选项并不是替代方案,而是针对不同情况的解决方案。如果您只是为了进行spike或poc,我肯定会选择第1个。如果您正在设置真正使用这些工件的严肃开发工作,您必须至少执行第3步,可能还要执行第2步;如果您确实要大量使用maven,则第2步对使您的生活更轻松至关重要。它也是一次很好的教育经验,因为大多数maven的东西在概念上都假设您拥有自己的存储库服务器。

所以这是我做的。 下载了gwt-dnd-3.1.1.jar并将其放置在与pom.xml相同的级别上,然后运行以下命令: sudo mvn install:install-file -DgroupId=com.google.code.gwt-dnd -DartifactId=gwt-dnd -Dversion=3.1.1 -Dpackaging=jar -Dfile=gwt-dnd-3.1.1.jar 结果 = 构建成功 现在我该怎么办?我仍然没有war文件,或者任何可执行文件来实际运行../target中的应用程序。 - kamal
我认为它不需要与pom.xml放在一起...另外,请验证它是否已安装到您的本地存储库;您可以通过查看.m2 / repository / my / maven / groupId / As / Directory / Structure / myArtifact来轻松完成此操作。 - chad
对于 Maven 中关键概念的简明澄清,给予一个很棒的 +1。 - Withheld

1

您需要了解如何在POM文件中配置存储库部分。

更好的做法是考虑设置一个Maven存储库管理器(如Nexus),以缓存和聚合构建所需的第三方存储库。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接