hibernatejpapersistencejava-ee-6war

what is the right path to refer a jar file in jpa persistence.xml in a web app?


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>

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

"WARNING: Unable to find file (ignored): file:.../../lib/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?


Solution

  • 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.