Almost forgot...not that this is too interesting, but the test case below
calls a method getJarURLFromURLEntry( ) -- this method is from
org.hibernate.ejb.packaging.JarVisitor.java, and it looks like this:

public static final URL getJarURLFromURLEntry(URL url, String entry) throws
IllegalArgumentException {
   URL jarUrl;
   String file = url.getFile();
   if ( ! entry.startsWith( "/" ) ) entry = "/" + entry;
   file = file.substring( 0, file.length() - entry.length() );
   if ( file.endsWith( "!" ) ) file = file.substring( 0, file.length() - 1
);
   try {
       String protocol = url.getProtocol();

       if ( "jar".equals( protocol )
               || "wsjar".equals( protocol ) ) { //Websphere has it's own
way
           jarUrl = new URL( file );
       }
       else if ( "zip".equals( protocol ) ) { //Weblogic has it's own way
           //we have extracted the zip file, so it should be read as a file
           jarUrl = new URL( "file", null, file );
       }
       else if ("code-source".equals( url.getProtocol() ) ) {
           //OC4J prevent ejb.jar access (ie everything without path
           //fix contributed by the community
           jarUrl = new File(file).toURL();
       }
       else {
           jarUrl = new URL( protocol, url.getHost(), url.getPort(), file
);
       }
   }
   catch (MalformedURLException e) {
       throw new IllegalArgumentException(
               "Unable to determine JAR Url from " + url + ". Cause: " +
e.getMessage()
       );
   }
   return jarUrl;
}

On 2/19/07, Davis Ford <[EMAIL PROTECTED]> wrote:

He, we're using maven 2.0.4 (although I just tried 2.0.5 and the same
problem exists), and we're using Hibernate Entity Manager 3.2.1-ga, and
we're on a Windows Platform.  These 3 things don't seem to work together.

The problem is the default repo for maven jars contains spaces on windows
C:\Documents and Settings\etc.

Hibernate Entity Manager expects to find META-INF\persistence.xml on the
classpath.  The general idea is to bury this in a jar that is loaded as a
dependency on our maven repo classpath, right?

Hibernate has code similar to this in
org.hibernate.ejb.EjbConfiguration.java (I added logger and assertions):

try {
        Enumeration<URL> xmls = Thread.currentThread()
        .getContextClassLoader()
        .getResources( "META-INF/persistence.xml" );

        if ( ! xmls.hasMoreElements() ) {
        fail( "Could not find any META-INF/persistence.xml file in the
classpath");
        }
        while ( xmls.hasMoreElements() ) {
        URL url = xmls.nextElement();
        LOGGER.debug( "Analyse of persistence.xml: " + url );
        URL jarURL = getJarURLFromURLEntry( url,
"/META-INF/persistence.xml" );
        assertFalse("Jar URL should not contain spaces, "+jarURL,
jarURL.toString().contains(" "));
        }

1. Create a jar-file, install it in local maven repo.
2. Add META-INF\persistence.xml to the jar file
3. Add a dependency to a new maven test project
4. Paste in code like above -- test case will always fail when it tests
for whitespace in the url.

System.out.println(Thread.currentThread().getContextClassLoader().getClass().getCanonicalName());


prints

org.apache.maven.surefire.booter.IsolatedClassLoader

If I run from Eclipse, I have no problems, and the above println prints
instead:

sun.misc.Launcher.AppClassLoader

I am *desperate* for any kind of solution to this problem that does not
require me to change the local maven repo to a url without spaces.

I need the URLClassLoader (IsolatedClassLoader) to correctly deal with
whitespace and replace it with %20.  If there is some other workaround --
please let me know.  Hibernate ends up throwing an exception and returning
null for the EntityManager which is an absolute show-stopper for us.

Thank you in advance,

Davis







--
Zeno Consulting, Inc.
http://www.zenoconsulting.biz
248.894.4922 phone
313.884.2977 fax

Reply via email to