0

I have a small project running fine in Eclipse. However when I package it in a jar it will fail with No Persistance provider.

I have tried with adding eclipselink as a maven dependency, external jar file and just as a normal project dependency in Eclipse. I have also tried to packaged with extract and package required libraries with no difference.

Worth noting is that the Jersey dependencies will work just fine and call the server with no problem. so those dependencies are working in the .jar file.

The Persistence.xml is located in
project/src/META-INF/persistence.xml

I have tried removing one of the persistance-unit without change.

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="TestMDB" transaction-type="RESOURCE_LOCAL">
        <class>com.sg.db.entity.Result</class>
        <properties>
            <property name="javax.persistence.jdbc.url" value="jdbc:ucanaccess://viking.mdb"/>
            <property name="javax.persistence.jdbc.driver" value="net.ucanaccess.jdbc.UcanaccessDriver"/>
        </properties>
    </persistence-unit>
    <persistence-unit name="TestMDBLive" transaction-type="RESOURCE_LOCAL">
        <class>com.sg.db.entity.Result</class>
        <properties>
            <property name="javax.persistence.jdbc.url" value="jdbc:ucanaccess://c:/Viking2001/DataBas/Viking.mdb"/>
            <property name="javax.persistence.jdbc.driver" value="net.ucanaccess.jdbc.UcanaccessDriver"/>
        </properties>
    </persistence-unit>
</persistence>

The project is a Maven project. It has external dependencies that I added with

<dependency>
 <groupId>ucanaccess</groupId>
 <artifactId>ucanaccess</artifactId>
 <scope>system</scope>
 <version>3.0.1</version>
 <systemPath>${project.basedir}/lib/ucanaccess-3.0.1.jar</systemPath>
</dependency>


No Persistence provider for EntityManager named TestMDBLive
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)

It will fail at the factory creation in the init()

public void init() {

        //Setup database connection
        try {
            factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
            em = factory.createEntityManager();

        } catch (Exception ex) {
            ex.printStackTrace();       }

    }
user2130951
  • 2,601
  • 4
  • 31
  • 58

2 Answers2

0

Try packaging your application with maven assembly plugin.

This will ensure that all dependencies are correctly placed into the jar archive

WeMakeSoftware
  • 9,039
  • 5
  • 34
  • 52
0

I had originally created a normal project that I used configure on and converted it to a maven project.

I re-created the project as a maven project from scratch and copied the resources over. After that the project ran correctly and eclipselink was also included.

To note is that the persistence.xml should still be in src/mail/java/META.INF with no need to move it.

user2130951
  • 2,601
  • 4
  • 31
  • 58