[jboss-user] [EJB 3.0] - Re: Exploded jar containing persistence.xml with jar-file el

jaikiran do-not-reply at jboss.com
Mon Mar 31 04:27:30 EDT 2008


I spent sometime on this, i can see where the problem is. There's a getRelativeURL method on org.jboss.ejb3.JmxDeploymentUnit class:

 public URL getRelativeURL(String jar)
  |    {
  |       URL url = null;
  |       try
  |       {
  |          url = new URL(jar);
  |       }
  |       catch (MalformedURLException e)
  |       {
  |          try
  |          {
  |             if (jar.startsWith(".."))
  |             {
  |                if (getUrl() == null)
  |                   throw new RuntimeException("relative <jar-file> not allowed when standalone deployment unit is used");
  |                String base = getUrl().toString();
  |                jar = jar.replaceAll("\\.\\./", "+");
  |                int idx = jar.lastIndexOf('+');
  |                jar = jar.substring(idx + 1);
  |                for (int i = 0; i < idx + 1; i++)
  |                {
  |                   int slash = base.lastIndexOf('/');
  |                   base = base.substring(0, slash + 1);
  |                }
  |                url = new URL(base + jar.substring(idx));
  |             }
  |             else
  |             {
  |                File fp = new File(jar);
  |                url = fp.toURL();
  |             }
  |          }
  |          catch (MalformedURLException e1)
  |          {
  |             throw new RuntimeException("Unable to find relative url: " + jar, e1);
  |          }
  |       }
  |       return url;
  |    }
  | 

This logic, using string manipulation, doesn't seem to work when the jar is exploded (i.e. ends with a / since its a directory ex: file:/D:/JBoss_4_2/server/default/deploy/EJB3Persistence.ear/myapp_ejb3.jar/) ). 

To get this working, i modified this piece of code in the JBoss code as follows:

  | public URL getRelativeURL(String jar)
  |    {
  |       URL url = null;
  |       try
  |       {
  |          url = new URL(jar);
  |       }
  |       catch (MalformedURLException e)
  |       {
  |          try
  |          {
  |             if (jar.startsWith(".."))
  |             {
  |                if (getUrl() == null)
  |                   throw new RuntimeException("relative <jar-file> not allowed when standalone deployment unit is used");
  |                String base = getUrl().toString();
  |                jar = jar.replaceAll("\\.\\./", "+");
  |                int idx = jar.lastIndexOf('+');
  |                jar = jar.substring(idx + 1);
  |                File file = new File(getUrl().getFile());
  |                
  |                for (int i = 0; i < idx + 1; i++)
  |                {
  |                  
  |             	   file = new File(file.getParent());
  |                }
  |                url = new URL(file.toURL().toString() + jar);
  |                
  |             }
  |             else
  |             {
  |                File fp = new File(jar);
  |                url = fp.toURL();
  |             }
  |          }
  |          catch (MalformedURLException e1)
  |          {
  |             throw new RuntimeException("Unable to find relative url: " + jar, e1);
  |          }
  |       }
  |       return url;
  |    }

Instead of relying on string manipulation i used the API available on java.io.File to parse the relative URL. I deployed the changed code in JBoss jar and was able to get my application deployed. Also, tested this change with an archived deployment (to make sure i did not break any existing behaviour), even that deployed fine.



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4140012#4140012

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4140012



More information about the jboss-user mailing list