在 web 应用程序中引用 jpa persistence.xml 中的 jar 文件的正确路径是什么? [英] what is the right path to refer a jar file in jpa persistence.xml in a web app?

查看:22
本文介绍了在 web 应用程序中引用 jpa persistence.xml 中的 jar 文件的正确路径是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

persistence.xml 看起来像这样:

persistence.xml looks like this:

<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.xmlWEB-INF/classes/META-INF文件夹.部署时,它只是告诉我

It is a web project, so the deployment unit is a war file. The jar file I tried to refer is in WEB-INF/lib/ folder , persistence.xml is in WEB-INF/classes/META-INF folder. When being deployed, it simply tells me

警告:无法找到文件(被忽略):文件:.../../lib/app-services-1.0.jar".

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

我也尝试了我能想到的所有可能的路径,即../lib/app-services-1.0.jarlib/app-services-1.0.jar>.

I also tried every possible path I could think of, i.e. ../lib/app-services-1.0.jar, lib/app-services-1.0.jar.

这样做的正确途径是什么?

What is the right path to do this?

推荐答案

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

just in case someone else stumbles upon this: the jar-file-statement is only valid. when the persistence-unit is deployed as part of an Enterprise Archives (.ear) - in every other case (.war), the persistence.xml must reside in /META-INF/ and cannot refrence classes that live outside the persistence-unit (see: http://javahowto.blogspot.com/2007/06/where-to-put-persistencexml-in-web-app.html). So, as far as I know, there is no way to have a persistence.xml living in WEB-INF/classes/META-INF that references classes that do not live in WEB-INF/classes.

这篇关于在 web 应用程序中引用 jpa persistence.xml 中的 jar 文件的正确路径是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆