META-INF/persistence.xml cannot be opened because it does not exist

爷,独闯天下 提交于 2019-12-06 14:44:53
Boris Treukhov

Your META-INF folder should be directly under the source folder, not to be the source folder by itself.

See Where do I put META-INF in Eclipse?

update From JPA 2.0 Specification

8.2 <...> A persistence unit is defined by a persistence.xml file. The jar file or directory whose META-INF directory contains the persistence.xml file is termed the root of the persistence unit. In Java EE environments, the root of a persistence unit must be one of the following:

  • an EJB-JAR file
  • the WEB-INF/classes directory of a WAR file
  • a jar file in the WEB-INF/lib directory of a WAR file
  • a jar file in the EAR library directory
  • an application client jar file

8.2.1 <...> A persistence.xml file defines a persistence unit. The persistence.xml file is located in the META-INF directory of the root of the persistence unit.

So it makes no difference how you configure your project, it's only the resulting jar that matters. If you're using maven, a common practice is to use src/main/resources folder for META-INF.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!