在向Maven添加依赖项时出现问题。

huangapple go评论72阅读模式
英文:

Problem when adding a dependency to maven

问题

我有一个非常基本的Spring Boot项目,其包含以下的 pom.xml 配置:

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <java.version>11</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        
        <!-- 此处省略其他依赖项 -->
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

我想要添加这个依赖项:https://search.maven.org/artifact/org.apache.hive/hive-jdbc/3.1.2/jar

所以我在依赖项中添加了:

<dependency>
    <groupId>org.apache.hive</groupId>
    <artifactId>hive-jdbc</artifactId>
    <version>3.1.2</version>
</dependency>

然而,当我在我的 pom.xml 中添加了这个依赖项后,我遇到了以下错误:

The project cannot be built until build path errors are resolved
The container 'Maven Dependencies' references non existing library
'/home/hduser/.m2/repository/jdk/tools/jdk.tools/1.6/jdk.tools-1.6.jar'
Missing artifact jdk.tools:jdk.tools:jar:1.6

我正在使用Java 11,我的IDE以及JAVA_HOME都设置为Java 11。请问我该如何解决这个问题?

编辑 1:

运行命令 mvn clean package 后出现以下错误信息:

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project dataanalytics: Could not resolve dependencies for project com.bla:dataanalytics:jar:0.0.1-SNAPSHOT: Could not find artifact jdk.tools:jdk.tools:jar:1.6 at specified path /usr/lib/jvm/java-11-openjdk-amd64/../lib/tools.jar -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
英文:

I have a very basic springboot project that has the following pom.xml

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&lt;parent&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
&lt;version&gt;2.3.4.RELEASE&lt;/version&gt;
&lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
&lt;/parent&gt;
&lt;properties&gt;
&lt;java.version&gt;11&lt;/java.version&gt;
&lt;/properties&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
&lt;scope&gt;runtime&lt;/scope&gt;
&lt;optional&gt;true&lt;/optional&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
&lt;artifactId&gt;lombok&lt;/artifactId&gt;
&lt;optional&gt;true&lt;/optional&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;exclusions&gt;
&lt;exclusion&gt;
&lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;
&lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;
&lt;/exclusion&gt;
&lt;/exclusions&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;

I want to add this dependency: https://search.maven.org/artifact/org.apache.hive/hive-jdbc/3.1.2/jar

So I added in the dependencies :

&lt;dependency&gt;
&lt;groupId&gt;org.apache.hive&lt;/groupId&gt;
&lt;artifactId&gt;hive-jdbc&lt;/artifactId&gt;
&lt;version&gt;3.1.2&lt;/version&gt;
&lt;/dependency&gt;

However, when I have this in my pom.xml, I have the following errors:

> The project cannot be built until build path errors are resolved
>
> The container 'Maven Dependencies' references non existing library
> '/home/hduser/.m2/repository/jdk/tools/jdk.tools/1.6/jdk.tools-1.6.jar'
>
> Missing artifact jdk.tools:jdk.tools:jar:1.6

I am using java 11 and my IDE as well as JAVA_HOME is set to java 11.

How can I solve this ?


Edit 1:

mvn clean package
------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.454 s
[INFO] Finished at: 2020-10-06T10:51:20+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project dataanalytics: Could not resolve dependencies for project com.bla:dataanalytics:jar:0.0.1-SNAPSHOT: Could not find artifact jdk.tools:jdk.tools:jar:1.6 at specified path /usr/lib/jvm/java-11-openjdk-amd64/../lib/tools.jar -&gt; [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

答案1

得分: 7

解释错误信息

> 在指定的路径中找不到 artifact jdk.tools:jdk.tools:jar:1.6
> 路径为 /usr/lib/jvm/java-11-openjdk-amd64/../lib/tools.jar

tools.jar 文件由 JDK 提供 - 看起来 1.6 是从包含的依赖项中引用的 - 建议您显式排除它:

&lt;dependency&gt;
&lt;groupId&gt;org.apache.hive&lt;/groupId&gt;
&lt;artifactId&gt;hive-jdbc&lt;/artifactId&gt;
&lt;version&gt;3.1.2&lt;/version&gt;
&lt;exclusions&gt;
&lt;exclusion&gt;
&lt;artifactId&gt;jdk.tools&lt;/artifactId&gt;
&lt;groupId&gt;jdk.tools&lt;/groupId&gt;
&lt;/exclusion&gt;
&lt;/exclusions&gt;
&lt;/dependency&gt;
英文:

Interpretting the error message

> Could not find artifact jdk.tools:jdk.tools:jar:1.6 at specified path
> /usr/lib/jvm/java-11-openjdk-amd64/../lib/tools.jar

The tools.jar file is supplied by the JDK - looks like 1.6 is referenced from the included dependency - suggest you explicitly exclude it:

&lt;dependency&gt;
&lt;groupId&gt;org.apache.hive&lt;/groupId&gt;
&lt;artifactId&gt;hive-jdbc&lt;/artifactId&gt;
&lt;version&gt;3.1.2&lt;/version&gt;
&lt;exclusions&gt;
&lt;exclusion&gt;
&lt;artifactId&gt;jdk.tools&lt;/artifactId&gt;
&lt;groupId&gt;jdk.tools&lt;/groupId&gt;
&lt;/exclusion&gt;
&lt;/exclusions&gt;
&lt;/dependency&gt;

huangapple
  • 本文由 发表于 2020年10月6日 16:46:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/64222313.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定