Jar存在于本地Maven仓库中,但仍然编译错误“包不存在”

问题描述 投票:0回答:1

hibernate-validator肯定是在pom.xml作为依赖:

<dependencies>
       ......
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
    </dependency>
</dependencies>


$ mvn dependency:tree | grep hibernate
[INFO] +- org.hibernate:hibernate-validator:jar:5.2.4.Final:runtime

并且jar肯定存在于本地文件系统repo中:

$ find /home/stewart/.m2/repository/ -name "hibernate-validator*"
/home/stewart/.m2/repository/org/hibernate/hibernate-validator-parent
/home/stewart/.m2/repository/org/hibernate/hibernate-validator-parent/5.2.4.Final/hibernate-validator-parent-5.2.4.Final.pom.sha1
/home/stewart/.m2/repository/org/hibernate/hibernate-validator-parent/5.2.4.Final/hibernate-validator-parent-5.2.4.Final.pom
/home/stewart/.m2/repository/org/hibernate/hibernate-validator
/home/stewart/.m2/repository/org/hibernate/hibernate-validator/5.2.4.Final/hibernate-validator-5.2.4.Final.pom.sha1
/home/stewart/.m2/repository/org/hibernate/hibernate-validator/5.2.4.Final/hibernate-validator-5.2.4.Final.pom
/home/stewart/.m2/repository/org/hibernate/hibernate-validator/5.2.4.Final/hibernate-validator-5.2.4.Final.jar
/home/stewart/.m2/repository/org/hibernate/hibernate-validator/5.2.4.Final/hibernate-validator-5.2.4.Final.jar.sha1

但仍然是这个编译失败:

$ mvn compile
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Project 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ project ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/stewart/workspace/project/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ project ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 15 source files to /home/stewart/workspace/project/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /home/stewart/workspace/project/src/main/java/project/entity/Entity.java:[3,43] package org.hibernate.validator.constraints does not exist
[ERROR] /home/stewart/workspace/project/src/main/java/project/entity/Entity.java:[15,10] cannot find symbol
  symbol:   class Email
  location: class project.entity.Entity
[INFO] 2 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

我试过了两个:

 mvn -U clean compile

 mvn dependency:purge-local-repository clean compile

.jar文件刚刚下载:

$ ll /home/stewart/.m2/repository/org/hibernate/hibernate-validator/5.2.4.Final/hibernate-validator-5.2.4.Final.jar 
-rw-rw-r-- 1 stewart stewart 704465 Mar  2 11:10 /home/stewart/.m2/repository/org/hibernate/hibernate-validator/5.2.4.Final/hibernate-validator-5.2.4.Final.jar

.jar确实包含电子邮件类:

$ unzip -l /home/stewart/.m2/repository/org/hibernate/hibernate-validator/5.2.4.Final/hibernate-validator-5.2.4.Final.jar | grep Email.class
 1377  2016-02-17 16:15   org/hibernate/validator/constraints/Email.class

为什么Maven找不到课程?

java maven compiler-errors dependencies
1个回答
1
投票

好像hibernate-validator有一个错误的范围。根据mvn依赖:treethe scope isruntime`和that means

运行 此范围表示编译不需要依赖项,但是用于执行。它位于运行时和测试类路径中,但不是编译类路径。

尝试更改范围以进行编译。

© www.soinside.com 2019 - 2024. All rights reserved.