Java Classpath Problems with Java 6 Update 11

Today I tracked down a nasty bug in Eclipselink JPA. To my upmost surprise this seems to be a problem with the classloader in Java. If the executing class is in a very deep path, e.g. C:\Documents and Settings\vogella1\Desktop\Documents8_MyDocuments\20_Documentation\WebpageExamples\de.vogella.jpa.bug\bin then the classloader does not find a resource in this class.

If you want to give it a try, below you find a small test class. I reported this at bugs.sun.com and got an incident number. So I have to wait what Suns says about this issue.

———————————————–
package de.vogella.jpa.bug;

import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;

public class Test {
public static void main(String[] args) {
ClassLoader currentLoader = Thread.currentThread()
.getContextClassLoader();
try {
Enumeration resources = currentLoader
.getResources(“META-INF/persistence.xml”);
while (resources.hasMoreElements()) {
System.out.println(“Elements found”);
resources.nextElement();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

About Lars Vogel

Lars Vogel is the founder and CEO of the vogella GmbH and works as Eclipse and Android consultant, trainer and book author. He is a regular speaker at international conferences, He is the primary author of vogella.com. With more than one million visitors per month this website is one of the central sources for Java, Eclipse and Android programming information.
This entry was posted in Uncategorized. Bookmark the permalink.