I met a "PersistenceException: error in opening zip file" error recently
when start a war with PU under WEB-INF/classes. The root cause is that
when PU_Root is "WEB-INF/classes" , the method
PersistenceUnitGBean.getPersistenceUnitRoot(Bundle, String)
will return a "jar:bundleentry://xxxxxxxxxx/Web-INF/classes!/" url which
can't be opened by openjpa. I committed following patch to fix this. But
I'm not very sure the logic in getPersistenceUnitRoot method.
Can anyone help review the if the logic below is correct ?
private static URL getPersistenceUnitRoot(Bundle bundle, String
persistenceUnitRoot) throws MalformedURLException {
if (persistenceUnitRoot == null || persistenceUnitRoot.equals("."))
{
*// PU was found in META-INF of bundle root*
return bundle.getEntry("/");
- } else if (persistenceUnitRoot.endsWith("/")) {
+ } else if (persistenceUnitRoot.endsWith("/")||
persistenceUnitRoot.endsWith("WEB-INF/classes")) {
*// PU was found in WEB-INF/classes of war bundle only ?*
return bundle.getEntry(persistenceUnitRoot);
} else {
*// U was found in lib/*.jar of war or ear bundle ?*
return new URL("jar:" + bundle.getEntry(persistenceUnitRoot) +
"!/");
}
On Wed, Feb 16, 2011 at 2:54 PM, <[email protected]> wrote:
> Author: genspring
> Date: Wed Feb 16 06:54:12 2011
> New Revision: 1071158
>
> URL: http://svn.apache.org/viewvc?rev=1071158&view=rev
> Log:
> OpenJPA can't handle the url when WEB-INF/classes PU was wrapped with
> "jar:" and "!/"
>
> Modified:
>
>
> geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/PersistenceUnitGBean.java
>
> Modified:
> geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/PersistenceUnitGBean.java
> URL:
> http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/PersistenceUnitGBean.java?rev=1071158&r1=1071157&r2=1071158&view=diff
>
> ==============================================================================
> ---
> geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/PersistenceUnitGBean.java
> (original)
> +++
> geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/PersistenceUnitGBean.java
> Wed Feb 16 06:54:12 2011
> @@ -165,7 +165,7 @@ public class PersistenceUnitGBean implem
> private static URL getPersistenceUnitRoot(Bundle bundle, String
> persistenceUnitRoot) throws MalformedURLException {
> if (persistenceUnitRoot == null || persistenceUnitRoot.equals("."))
> {
> return bundle.getEntry("/");
> - } else if (persistenceUnitRoot.endsWith("/")) {
> + } else if (persistenceUnitRoot.endsWith("/")||
> persistenceUnitRoot.endsWith("WEB-INF/classes")) {
> return bundle.getEntry(persistenceUnitRoot);
> } else {
> return new URL("jar:" + bundle.getEntry(persistenceUnitRoot) +
> "!/");
>
>
>
--
Shawn