EclipseLinke:没有名为META-INF / services / javax.persistence.spi的资源文件:找不到PersistenceProvider

时间:2013-09-15 17:11:06

标签: java eclipse maven jpa eclipselink

我正在使用EclipseLink,甚至我已经使用maven导入了所有必需的jar文件,我仍然得到例外:

  

线程“main”中的异常javax.persistence.PersistenceException:否   资源文件命名   META-INF / services / javax.persistence.spi.PersistenceProvider是   找到。请确保持久性提供程序jar文件位于   你的类路径。

在Maven pom我有依赖:

<dependency>
      <groupId>javax.persistence</groupId>
      <artifactId>persistence-api</artifactId>
      <version>1.0.2</version>
      <scope>provided</scope>
</dependency>

这是我的persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
    xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="PersistenzJPAProjekt">
     <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>com.testJPABasis.Person</class>

    </persistence-unit>
</persistence>

这里是日食中的clathpath: enter image description here

实际生成异常的类:

public class TestJPA
{
    public static void main(String[] args)
    {
        Person person = new Person();
        person.setPersonID(1);

        EntityManagerFactory emf = Persistence.createEntityManagerFactory("PersistenzJPAProjekt");
        EntityManager em = emf.createEntityManager();

    }
}

persistence.xml直接位于META-INF下。据我所知,我不需要Glassfish或Tomcat,因为EclipseLink是为独立应用程序而制作的。如果我错了,也许这就是原因。 Meta-Inf被放置在:

enter image description here

1 个答案:

答案 0 :(得分:2)

persistence-api就是这样的:API(主要是接口)。您仍然需要包含实际的持久性提供程序;看起来你想要EclipseLink。