简体   繁体   English

jar文件中EntityManagerFactory的Persistence.xml文件

[英]Persistence.xml file of EntityManagerFactory in a jar file

Is there any way to put content of persistence.xml file to the source code that calling EntityManagerFactory? 有什么方法可以将persistence.xml文件的内容放入调用EntityManagerFactory的源代码中? I tried building a project that contain persistence.xml but when I call the it from another project I always get this error: 我尝试构建一个包含persistence.xml的项目,但是当我从另一个项目中调用它时,总是会遇到此错误:

[PersistenceException: No Persistence provider for EntityManager named cassandra_pu]

I also extract the jar file to check whether the xml file is included or not, it;s included in the WEB-INF folder. 我还提取了jar文件,以检查XML文件是否包含在WEB-INF文件夹中。 To me it's really weird because the persistence.xml is already in the jar file, why it keeps asking for the xml file? 对我来说,这真的很奇怪,因为persistence.xml已经在jar文件中,为什么它不断要求XML文件?

The persistence.xml file must be in the root of your classpath. persistence.xml文件必须位于类路径的根目录中。 WEB-INF is not in the root of the class-path. WEB-INF不在类路径的根目录中。 If you want to put it in a .jar file, place it in WEB-INF/lib, if you want to have it outside a .jar file, place it in WEB-INF/classes. 如果要将其放在.jar文件中,请将其放在WEB-INF / lib中;如果要将其放在.jar文件之外,则将其放在WEB-INF / classes中。 If you use JPA2 you no longer need that file. 如果使用JPA2,则不再需要该文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM