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找不到课程?
答案 0 :(得分:1)
似乎hibernate-validator
的范围有误。根据mvn依赖:tree the scope is
runtime`和that means:
<强>运行时强>
此范围表示编译不需要依赖项,但是用于执行。它位于运行时和测试类路径中,但不是编译类路径。
尝试将范围更改为编译。