我有一個在Eclipse中運行良好的小項目。但是,當我將它打包在一個jar中時,它將會失敗,並顯示No Persistance提供程序。沒有用eclipselink命名的EntityManager的持久性提供者
我已經嘗試添加eclipselink作爲maven依賴項,外部jar文件和Eclipse中的正常項目依賴項。我也嘗試打包提取和包所需的庫沒有區別。
值得注意的是澤西島的依賴關係可以正常工作,並且可以毫無問題地調用服務器。所以這些依賴關係在.jar文件中工作。
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>
該項目是一個Maven項目。它有我添加了
<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)
外部依賴它會在工廠設立在init失敗()
public void init() {
//Setup database connection
try {
factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
em = factory.createEntityManager();
} catch (Exception ex) {
ex.printStackTrace(); }
}
你如何打包你的應用程序? – WeMakeSoftware
作爲Eclipse中的可運行jar – user2130951
嘗試在您的持久性單元配置中放置' org.eclipse.persistence.jpa.PersistenceProvider '。 –