0

我在多模块 Maven 项目中遇到错误。我尝试通过 eclipse run 作为选项运行“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 错误?

4

2 回答 2

0

实际上存在对javax.persistence. 这与 JPA 实现(在您的情况下为 Hibernate)一起使用。

将此添加到您的pom.xml

<dependency>
   <groupId>javax.persistence</groupId>
   <artifactId>persistence-api</artifactId>
   <version>1.0</version>
   <optional>true</optional>
</dependency>
于 2012-12-11T23:13:01.013 回答
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-jdk14logback-classic绑定必须在 rhw 类路径中。

于 2013-01-17T23:25:59.097 回答