Hello Aleksandr:
The place for persistence.xml is in the /WEB-INF/classes/
unlike the jar file where the default class path is at the root of the
jar /META-INF. When dealing with war, the default class path /WEB-INF/classes
and that's where the search starts.
According to servlet specs, the META-INF class should be at the root
/META-INF and contains MANIFEST.MF
If you have an ejb jar and you have the persistence.xml in
/META-INF/persistence.xml it should work, but this is not the case for
war files.
On Sat Dec 25,2010 06:49 pm, Aleksandr Ivanov wrote:
> Hello list,
>
> I'm trying to deploy a simple ejb-application (packaged to war) to
> Tomee 6.0.29 (vanilla download) and I encountered some "strange"
> behavior that might be a bug.
>
> When my application was packaged the standard way
>
> root.war/
> --/META-INF
> ---->persistence.xml
> --/WEB-INF
> ---->web.xml
> ---->classes/l
> ....
>
> Openejb could not deploy it. In the log files I found the following:
>
> ERROR - FAIL ... ListenerDaoBean: Missing required persistence.xml
> for @PersistenceContext ref "xxx" to unit "xxx".
> ...
> ...
> ...
> ERROR - Unable to deploy collapsed ear in war /test-app-1.0-SNAPSHOT:
> Exception: Module failed validation.
>
>
> After a small debugging session I found out that the class responsible
> for locating persistence.xml file is
> org.apache.openejb.tomcat.catalina.TomcatWebAppBuilder.
> //snippet line:595-597 from TomcatWebAppBuilder
> ResourceFinder finder = new ResourceFinder("",
> standardContext.getLoader().getClassLoader());
> //standardContext.getLoader().getClassLoader() returns
> root.war/WEB-INF/classes instead of root.war/
> List<URL> persistenceUrls = finder.findAll("META-INF/persistence.xml");
> appModule.getAltDDs().put("persistence.xml", persistenceUrls);
>
> When I placed persistence.xml in
> root.war/WEB-INF/classes/META-INF/persistence.xml the problem was
> gone and application loaded correctly.
>
> Is this desired behavior or should I file a bug report?
>
> Best,
>
> --
> Aleksandr Ivanov