Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
282 views
in Technique[技术] by (71.8m points)

java - Where to put persistence.xml in library jar using maven?

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.

All projects are configured using 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)

'''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 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

I suspect the persistence.xml is not found, but it is present in the target jar.

question from:https://stackoverflow.com/questions/10871109/where-to-put-persistence-xml-in-library-jar-using-maven

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...