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/classes/META-INF文件夹中,WEB-INF/lib/文件夹中,persistence.xml在jar文件夹中。在部署时,它只是简单地告诉我
“警告:找不到文件(忽略):文件:.../../lib/app-services-1.0.jar”。
我还尝试了我能想到的所有可能的方法,例如../lib/app-services-1.0.jar,lib/app-services-1.0.jar.
做这件事的正确路径是什么?
发布于 2011-06-29 22:25:36
以防其他人偶然发现:jar-file-语句只是有效的。当持久性单元被部署为企业档案(.ear)的一部分时--在其他情况下(.war),persistence.xml必须驻留在/META-INF/中,并且不能引用持久性单元之外的类(参见:http://javahowto.blogspot.com/2007/06/where-to-put-persistencexml-in-web-app.html)。因此,据我所知,不可能有一个类位于WEB-INF/ persistence.xml /META-INF中,它引用的类不在WEB-INF/classes中。
发布于 2013-05-12 11:21:31
看一看jsr总是有效的!
除了在mapping-file
元素中指定的映射文件之外,还可以使用jar-file
元素来指定一个或多个JAR文件。如果指定,将在这些JAR文件中搜索托管持久性类,并且将处理在这些JAR文件上找到的任何映射元数据注释,或者使用本规范定义的映射注释默认值来映射它们。这样的JAR文件是相对于包含持久性单元的根的目录或jar文件指定的。
下面的示例说明如何使用jar-file
元素引用其他持久性类。
Example 1:
app.ear
lib/earEntities.jar
earRootPUnit.jar (with META-INF/persistence.xml )
persistence.xml contains:
<jar-file>lib/earEntities.jar</jar-file>
Example 2:
app.ear
lib/earEntities.jar
lib/earLibPUnit.jar (with META-INF/persistence.xml )
persistence.xml contains:
<jar-file>earEntities.jar</jar-file>
Example 3:
app.ear
lib/earEntities.jar
ejbjar.jar (with META-INF/persistence.xml )
persistence.xml contains:
<jar-file>lib/earEntities.jar</jar-file>
Example 4:
app.ear
war1.war
WEB-INF/lib/warEntities.jar
WEB-INF/lib/warPUnit.jar (with META-INF/persistence.xml )
persistence.xml contains:
<jar-file>warEntities.jar</jar-file>
Example 5:
app.ear
war2.war
WEB-INF/lib/warEntities.jar
WEB-INF/classes/META-INF/persistence.xml
persistence.xml contains:
<jar-file>lib/warEntities.jar</jar-file>
Example 6:
app.ear
lib/earEntities.jar
war2.war
WEB-INF/classes/META-INF/persistence.xml
persistence.xml contains:
<jar-file>../../lib/earEntities.jar</jar-file>
Example 7:
app.ear
lib/earEntities.jar
war1.war
WEB-INF/lib/warPUnit.jar (with META-INF/persistence.xml )
persistence.xml contains:
<jar-file>../../../lib/earEntities.jar</jar-file>
正如您所看到的,这里没有war文件的示例,上面示例中的所有war文件都在ear文件中!
但是我在war文件中进行了测试,只有当我指定jar文件的绝对路径时,它才能工作,对于生产环境来说,这不是一个好方法!
发布于 2015-12-26 01:29:37
war2.war
WEB-INF/lib/warEntities.jar
WEB-INF/classes/META-INF/persistence.xml
persistence.xml contains:
<jar-file>lib/warEntities.jar</jar-file>
此格式适用于war文件。我正在使用Wildlfy 8.2.0和JPA 2.1
https://stackoverflow.com/questions/4433341
复制相似问题