0

I have an issue with a Java program. When I run the program from Eclipse (Run or Debug) it works fine. But, when I try to run the exported JAR file it gives me the following error:

977 INFO [main] openjpa.Runtime - Starting OpenJPA 2.4.2 The persistence provider is attempting to use properties in the persistence.xml file to resolve the data source. A Java Database Connectivity (JDBC) driver or data source class name must be specified in the openjpa.ConnectionDriverName or javax.persistence.jdbc.driver property. The following properties are available in the configuration: "org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl@2655aabb".

I checked that the persistence.xml is in the correct place (src/META-INF) in the JAR file.

This is my persistence.xml:

<persistence-unit name="JPA" transaction-type="RESOURCE_LOCAL">

  <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
  <class>class_name_here</class>
  <class>class_name_here</class>

  <properties>

    <property name="openjpa.RuntimeUnenhancedClasses" value="unsupported" />

    <!-- Production -->
    <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
    <property name="javax.persistence.jdbc.url" value="jdbc:mysql://server:port/database" />
    <property name="javax.persistence.jdbc.user" value="user" />
    <property name="javax.persistence.jdbc.password" value="password" />

  </properties>

*I removed the values from the properties, but in the original file they are there and they are correct (it runs from within Eclipse).

  • Does this help? https://stackoverflow.com/questions/19785804/how-export-java-jar-from-eclipse-with-dependencies-on-other-jars – crizzis Jun 20 '17 at 10:02
  • Thanks for the help. I was using option "Package required libraries into generated JAR". I tried per the instructions in the link and now it is telling me "No persistence providers available for "JPA" after trying the following descovered implementation: org.eclipse.persistence.jpa.PersistenceProvider" – jgrodrigueza Jun 20 '17 at 15:23
  • You've declared OpenJPA as your persistence provider (`org.apache.openjpa.persistence.PersistenceProviderImpl`) but the error mentions EclipseLink (`discovered implementation: org.eclipse.persistence.jpa.PersistenceProvider`) so, which is it? Which JPA implementation is available on the classpath? – crizzis Jun 20 '17 at 15:29
  • Thanks. It would be JPA. I found some extra libs in my classpath and made some cleanup, but the error is the original. So far, these are the only 2 libs in my classpath: mysql-connector-java-5.0.8-bin.jar openjpa-all-2.4.2.jar *There are others that were added through maven but those are for logging and Twitter, nothing related to persistence. – jgrodrigueza Jun 21 '17 at 04:50
  • Try adding OpenJPA and MySQL Connector to Maven dependencies and removing the standalone dependencies from build path – crizzis Jun 21 '17 at 08:22
  • I already did, the outcome did not change. – jgrodrigueza Jun 21 '17 at 13:40
  • Thanks. I decided to recreate the project as a new Maven project and that solved the issue (maybe something was stuck or misconfigured in old project). – jgrodrigueza Jun 22 '17 at 03:30

1 Answers1

0

Recreating the project from scratch solved the issue.