问题描述
在工作中,我们有一个实体库,供几个客户端用于库(多个servlet,桌面应用程序等)。实体库由JPA-Annotated类组成,最突出的是persistence.xml。
At work we have an entity library which is used by several clients for the library (several servlets, a desktop application, etc.). The entity library consists of JPA-Annotated classes and most prominently a persistence.xml.
所有项目都是使用maven配置的。
All projects are configured using maven.
应该在哪里放置persistence.xml文件?它需要位于该实体库的jar文件中,我不知道如何使用maven配置它。
Where should a persistence.xml file be put? It needs to be located inside the jar file of that entity library and I'm not sure how to configure this using maven.
(我们只是将项目拆分为几个较小的项目)
(We are just splitting up a project into several smaller projects)
''''更新'''要清楚这一点,有一个Maven-Project A包含persistence.xml,另一个包含(B)这取决于该项目。我把persistence.xml放在A中的src / main / resources / META-INF / persistence.xml中,当试图在A里面使用一个EntityManager时没问题,insidie B:没什么用。
'''UPDATE''' To be clear about this, there is one Maven-Project A containing the persistence.xml and another one (B) which depends on that Project. I've places persistence.xml in src/main/resources/META-INF/persistence.xml in A, when trying to use an EntityManager inside A, no problem, insidie B: nothing works.
EclipseLink提供以下警告:
EclipseLink gives the following Warning:
[EL Warning]: The collection of metamodel types is empty. Model classes may not have been found during entity search for Java SE and some Java EE container managed persistence units. Please verify that your entity classes are referenced in persistence.xml using either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element
我怀疑找不到persistence.xml,但它存在于目标jar中。
I suspect the persistence.xml is not found, but it is present in the target jar.
推荐答案
@Dave提到上面 src / main / resources
就是这个地方。当谈到 persistence.xml
时,它应放在 META-INF
文件夹中。总结如下: src / main / resources / META-INF / persistence.xml
。
As @Dave mentions above src/main/resources
is the place. When it comes to persistence.xml
it should be placed in the META-INF
folder. So to conclude: src/main/resources/META-INF/persistence.xml
.
这篇关于在哪里使用maven将persistence.xml放在库jar中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!