转载

hibernate – 在web应用程序中在jpa persistence.xml中引用jar文件的正确路径是什么?

persistence.xml如下所示:

<persistence-unit name="testPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <non-jta-data-source>jdbc/test</non-jta-data-source>
    <jar-file>../../lib/app-services-1.0.jar</jar-file>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
</persistence-unit>

它是一个Web项目,因此部署单元是一个war文件.

我试图引用的jar文件是在WEB-INF / lib /文件夹中,persistence.xml在WEB-INF / classes / META-INF文件夹中.在部署时,它只是告诉我

“WARNING: Unable to find file (ignored): file:…/../lib/app-services-1.0.jar”.

我也尝试了我可以想到的每一个可能的路径,即../lib/app-services-1.0.jar,lib / app-services-1.0.jar.

什么是正确的道路呢?

以防万一有人绊倒:jar-file-statement只能有效.当持久性单元被部署为企业档案(.ear)的一部分时,在其他情况下(.war),persistence.xml必须驻留在/ META-INF /中,并且不能引用生存在持久单元之外的类(见: http://javahowto.blogspot.com/2007/06/where-to-put-persistencexml-in-web-app.html ).所以,据我所知,没有办法让一个persistence.xml生活在WEB-INF / classes / META-INF中,引用不在WEB-INF / classes中的类.

代码日志版权声明:

翻译自:http://stackoverflow.com/questions/4433341/what-is-the-right-path-to-refer-a-jar-file-in-jpa-persistence-xml-in-a-web-app

原文  https://codeday.me/bug/20181016/288075.html
正文到此结束
Loading...