我的 Java 程序有问题。当我从 Eclipse 运行该程序(运行或调试)时,它工作正常。但是,当我尝试运行导出的 JAR 文件时,出现以下错误:
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".
我检查了 persistence.xml 是否位于 JAR 文件中的正确位置 (src/META-INF)。
这是我的 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>
*我从属性中删除了这些值,但在原始文件中它们仍然存在并且是正确的(它在 Eclipse 中运行)。
最佳答案
从头开始重新创建项目解决了该问题。
关于java - JPA 可在 Eclipse 上运行,但不能在 JAR 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44644563/