Search code examples
javaeclipsemavenjpaeclipselink

EclipseLinke:No resource files named META-INF/services/javax.persistence.spi:No PersistenceProvider were found


I am using EclipseLink and even I have all necessary jar files imported with maven, I get still the Exception:

Exception in thread "main" javax.persistence.PersistenceException: No resource files named META-INF/services/javax.persistence.spi.PersistenceProvider were found. Please make sure that the persistence provider jar file is in your classpath.

In Maven pom I have the dependency:

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

Here is my 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>

Here the clathpath in eclipse: enter image description here

The class which actually generates the exception:

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();

    }
}

The persistence.xml is directly under META-INF. As far as I know I don't need to have Glassfish or Tomcat as EclipseLink is made for standalone applications. If I am wrong maybe this is then the cause. The Meta-Inf is placed in:

enter image description here


Solution

  • persistence-api is just that: the API (mostly interfaces). You still need to include the actual persistence provider; it looks like you're wanting EclipseLink.