我在多模块maven项目中遇到错误。 我试图通过eclipse运行“maven install”作为选项。
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mysite-entities 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ mysite-entities ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/thomas/spring/mysite-parent/mysite-entities/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ mysite-entities ---
[INFO] Compiling 11 source files to /home/thomas/spring/mysite-parent/mysite-entities/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/thomas/spring/mysite-parent/mysite-entities/src/main/java/com/mysite/entities/Mcc.java:[5,24] package javax.persistence does not exist
[ERROR] /home/thomas/spring/mysite-parent/mysite-entities/src/main/java/com/mysite/entities/Mcc.java:[6,24] package javax.persistence does not exist
[ERROR] /home/thomas/spring/mysite-parent/mysite-entities/src/main/java/com/mysite/entities/Mcc.java:[8,1] cannot find symbol
symbol: class Entity
@Entity
Mcc.java:
package com.mysite.entities;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Mcc implements Serializable
{
/**
*
*/
private static final long serialVersionUID = 4146710247449711520L;
@Id
private Long id;
private String name;
public Long getId()
{
return id;
}
public void setId(Long id)
{
this.id = id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
我的pom.xml包括:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
我已经检查了拉入的maven依赖项,它们包括hibernate-jpa-2.0-api-1.0.1.Final.jar,它又包含了所有必需的类。
为什么我会收到这个maven错误?
答案 0 :(得分:0)
javax.persistence
实际上存在依赖关系。这与JPA实现(在您的情况下为Hibernate)相关。
将此添加到您的pom.xml
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
<optional>true</optional>
</dependency>
答案 1 :(得分:0)
在某个地方找到这个帖子,发现这个消除了警告信息。
将slf4j-api-VERSION.jar
和logback-classic-VERSION.jar
复制到%JAVA_HOME%\jre\lib\ext
slf4j-api-VERSION.jar
位于%M2_REPOSITORY%\org\slf4j\slf4j-api\VERSION\
logback-classic-VERSION.jar
位于%M2_REPOSITORY%\ch\qos\logback\logback-classic\VERSION\
如果不使用logback-classic,则至少slf4j-log4j12
,slf4j-simple
,slf4j-jdk14
或logback-classic
绑定必须位于rhw类路径中。