java - JPA 可在 Eclipse 上运行,但不能在 JAR 上运行

标签 java mysql jpa jar

我的 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/

相关文章:

java - 检测参数字符串的代码行

Java - 尝试创建简单的文件传输服务时遇到问题

java - 在 PHP 和 Java 中使用套接字

php - 我在日志中遇到错误,但是脚本可以满足我的要求

java - JPA 和 Spring 的手动事务服务和 DAO 层

database - JPA/Hibernate区别MappedSuperclass和实体抽象类

java - "Ant not recognized as an internal or external command"- 开发Spring应用教程

mysql:启动服务器时出现权限错误

MySQL查询获取m中的所有外键及其所有列的总和:n table

java - 在 Hibernate 中将实体字段子集映射为单独的类的有效方法