如何解决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

请帮我解决这个问题。

谢谢!!

你不能直接输入jar的名称。groupId 大多数时候引用"包",而 artifactId 引用依赖项的名称。要获取示例,请转到 http://mvnrepository.com/artifact/com.sun.jersey/jersey-core/1.18.3

您可以使用

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

放在 .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>

欲了解更多信息,请看这里

最新更新