DelegatingClassLoader extends ClassLoader { @Override public Enumeration<URL> getResources(String name) throws IOException { DelegateEnumeration<URL> ret = new DelegateEnumeration<URL>(); for (ClassLoader delegate : delegates) { Enumeration<URL> e = delegate.getResources(name); if (e != null) { if (e.hasMoreElements()) { ret.addEnumeration(e); continue; } } if (log.isTraceEnabled()) { log.trace("URL " + name + " not found with classloader: " + delegate + ". Trying other delegates"); } } return ret; } DelegatingClassLoader(ClassLoader... delegates); @Override InputStream getResourceAsStream(String name); @Override URL getResource(String name); @Override Enumeration<URL> getResources(String name);  }
@Test public void testGetResources() throws IOException { ClassLoader cl = new DelegatingClassLoader(clOne, clTwo, clThree); List<URL> propsUrls = loadResources(cl, "test.properties", 3); URL url = propsUrls.get(0); String val = loadProperty(url, "key"); Assert.assertEquals("one", val); url = propsUrls.get(1); val = loadProperty(url, "key"); Assert.assertEquals("two", val); url = propsUrls.get(2); val = loadProperty(url, "key"); Assert.assertEquals("three", val); propsUrls = loadResources(cl, "nonexisting", 0); propsUrls = loadResources(cl, "test.conf", 1); url = propsUrls.get(0); val = loadProperty(url, "key"); Assert.assertEquals("test.conf", val); propsUrls = loadResources(cl, "sub/test.properties", 1); url = propsUrls.get(0); val = loadProperty(url, "key"); Assert.assertEquals("sub one", val); cl = new DelegatingClassLoader(clTwo, clThree, clOne); propsUrls = loadResources(cl, "test.properties", 3); url = propsUrls.get(0); val = loadProperty(url, "key"); Assert.assertEquals("two", val); url = propsUrls.get(1); val = loadProperty(url, "key"); Assert.assertEquals("three", val); url = propsUrls.get(2); val = loadProperty(url, "key"); Assert.assertEquals("one", val); propsUrls = loadResources(cl, "sub/test.properties", 1); url = propsUrls.get(0); val = loadProperty(url, "key"); Assert.assertEquals("sub one", val); }