Search code examples
javamavenclassloader

Classloader.getResources() in maven project returns an empty Enumeration


I have some code which gets resources as follows:

public static final String CONVERTER_FILE = "META-INF/jumbo-converters";
static {
        ClassLoader ldr = Thread.currentThread().getContextClassLoader();
        Enumeration<URL> e = ldr.getResources(CONVERTER_FILE);

but when I run this in a JUnit test (Java 6) the enumeration is empty. There are a number of subprojects in the project which have the following file:

myProject/mySubProject/src/main/resources/META-INF/jumbo-converters

and I believe that it has worked in the past. What does getResources do? and how can I debug its current failure?


Solution

  • The resources for a module (sub-project) will not be added to the classpath of the aggregating project unless the aggregating project has a dependency on the module. Being a module to a project does not establish a dependency relationship in either direction.

    In your case above you should add a dependency on mySubProject to myProject. Thus making myProject depend on mySubProject.