【问题标题】:Hibernate configuration file : Archive for required library persistence.xml cannot be readHibernate 配置文件:无法读取所需库 persistence.xml 的存档
【发布时间】:2020-01-26 15:29:56
【问题描述】:

我尝试了在 stackoverflow 上找到的所有答案,但没有一个适合我的问题:

归档所需库: 项目“项目”中的“src/main/resources/META-INF/persistence.xml” 无法读取或不是有效的 ZIP 文件

我的休眠配置文件“persistence.xml”直接在 src/main/resources 的 META-INF 文件夹中,但 Eclipse 继续告诉我存在构建路径问题。

这里是内容:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">
   <persistence-unit name="app.shellx.jpa">
<!--       <jta-data-source>java:/DefaultDS</jta-data-source> -->
      <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL9Dialect"/>
         <property name="hibernate.hbm2ddl.auto" value="validate"/>        
      </properties>
   </persistence-unit>
</persistence>

persistence.xml 被显式添加到构建路径中:

此外,Eclipse 会打印出很多我无法这样编码的错误弹出窗口。

【问题讨论】:

  • 你不必将它添加为库(它不是一个),只需将它留在你的资源文件夹中,看看它是否有效
  • 我不知道为什么它以前不起作用,但你解决了我的问题。我觉得很愚蠢。
  • 我会把我的评论移到一个答案上,请接受它,以便其他人也能找到它。

标签: java eclipse hibernate maven corrupt


【解决方案1】:

您不必将其添加为库,只需将其保留在资源文件夹中即可。

【讨论】:

    猜你喜欢
    • 2013-10-31
    • 2014-02-01
    • 2012-02-10
    • 1970-01-01
    • 2019-01-24
    • 1970-01-01
    • 2018-06-27
    • 2019-01-08
    • 2013-10-04
    相关资源
    最近更新 更多