如何解决pom.xml中的依赖错误

时间:2015-01-18 16:22:19

标签: maven pom.xml

我是maven的新手,我在pom.xml文件中添加依赖项时遇到此错误。下面是我的pom.xml文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>CrunchifyRESTJerseyExample</groupId>
  <artifactId>CrunchifyRESTJerseyExample</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <dependencies>
    <dependency>
        <groupId>asm.jar</groupId>
        <artifactId>asm.jar</artifactId>
        <version>3.3.1</version>
    </dependency>
    <dependency>
        <groupId>jersey-bundle.jar</groupId>
        <artifactId>jersey-bundle.jar</artifactId>
        <version>1.18.1</version>
    </dependency>
    <dependency>
        <groupId>json.jar</groupId>
        <artifactId>json.jar</artifactId>
        <version>20140107</version>
    </dependency>
    <dependency>
        <groupId>jersey-core.jar</groupId>
        <artifactId>jersey-core.jar</artifactId>
        <version>1.18.1</version>
    </dependency>
    <dependency>
        <groupId>jersey-bundle</groupId>
        <artifactId>jersey-bundle</artifactId>
        <version>1.18.1</version>
    </dependency>
  </dependencies>
</project>

对于每个依赖项,都会显示错误

Missing artifact json.jar:json.jar:jar:20140107
Missing artifact asm.jar:asm.jar:jar:3.3.1
Missing artifact jersey-bundle.jar:jersey-bundle.jar:jar:1.18.1
Missing artifact jersey-bundle:jersey-bundle:jar:1.18.1
Missing artifact jersey-core.jar:jersey-core.jar:jar:1.18.1

请帮我解决这个问题。

谢谢!

3 个答案:

答案 0 :(得分:1)

你不能直接把罐子的名字。 groupId指&#34;包&#34;大部分时间和artifactId为依赖项的名称。 举个例子,请转到http://mvnrepository.com/artifact/com.sun.jersey/jersey-core/1.18.3

答案 1 :(得分:0)

在.m2目录中放置setting.xml,您可以在其中声明应该找到依赖项jar的存储库。

<settings>
 ...
 <profiles>
   ...
   <profile>
     <id>myprofile</id>
     <repositories>
       <repository>
         <id>my-repo2</id>
         <name>your custom repo</name>
         <url>http://jarsm2.dyndns.dk</url>
       </repository>
     </repositories>
   </profile>
   ...
 </profiles>

 <activeProfiles>
   <activeProfile>myprofile</activeProfile>
 </activeProfiles>
 ...
</settings>

和镜像示例

  <mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository.
     | The repository that this mirror serves has an ID that matches the
     | mirrorOf element of this mirror. IDs are used for inheritance and direct
     | lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
  </mirrors>

了解更多信息,请查看here

答案 2 :(得分:0)

您可以使用http://search.maven.org/查找依赖关系的正确坐标(即groupId + artifactId + version)。 如果您的系统上已经有这些罐子,您可以使用带有校验和的http://search.maven.org/#advancedsearch%7Cgav SHA1,并且它会为您提供匹配的坐标(如果在Maven Central中可用的话)。