10 abr. 2012

JPA setup: entities in JAR file

In this post, we'll see how to package our entities in a JAR file that will be used as a dependency for a WAR webapp file.

The setup is really simple, but a bit tricky too. The key is to place persistence.xml file in the META-INF folder of the JAR file, along with our entities. We should end up with the following directory tree:
my-core.jar:
META-INF/persistence.xml
bar/foo/MyEntity.class
//other core files

my-webapp.war:
WEB-INF/lib/my-core.jar
WEB-INF/web.xml
//other webapp files
That's it. We can now easily package our webapps as multi-module projects (eg Maven).

No hay comentarios: