@Test public void testGetResource() throws IOException { URL testJar = makeTestJar().toURI().toURL(); ClassLoader currentClassLoader = getClass().getClassLoader(); ClassLoader appClassloader = new ApplicationClassLoader( new URL[] { testJar }, currentClassLoader, null); assertNull("Resource should be null for current classloader", currentClassLoader.getResourceAsStream("resource.txt")); InputStream in = appClassloader.getResourceAsStream("resource.txt"); assertNotNull("Resource should not be null for app classloader", in); assertEquals("hello", IOUtils.toString(in)); }
@Override public URL getResource(String name) { URL url = null; if (!isSystemClass(name, systemClasses)) { url= findResource(name); if (url == null && name.startsWith("/")) { if (LOG.isDebugEnabled()) { LOG.debug("Remove leading / off " + name); } url= findResource(name.substring(1)); } } if (url == null) { url= parent.getResource(name); } if (url != null) { if (LOG.isDebugEnabled()) { LOG.debug("getResource("+name+")=" + url); } } return url; }
ApplicationClassLoader extends URLClassLoader { @Override public URL getResource(String name) { URL url = null; if (!isSystemClass(name, systemClasses)) { url= findResource(name); if (url == null && name.startsWith("/")) { if (LOG.isDebugEnabled()) { LOG.debug("Remove leading / off " + name); } url= findResource(name.substring(1)); } } if (url == null) { url= parent.getResource(name); } if (url != null) { if (LOG.isDebugEnabled()) { LOG.debug("getResource("+name+")=" + url); } } return url; } }
ApplicationClassLoader extends URLClassLoader { @Override public URL getResource(String name) { URL url = null; if (!isSystemClass(name, systemClasses)) { url= findResource(name); if (url == null && name.startsWith("/")) { if (LOG.isDebugEnabled()) { LOG.debug("Remove leading / off " + name); } url= findResource(name.substring(1)); } } if (url == null) { url= parent.getResource(name); } if (url != null) { if (LOG.isDebugEnabled()) { LOG.debug("getResource("+name+")=" + url); } } return url; } ApplicationClassLoader(URL[] urls, ClassLoader parent,
      List<String> systemClasses);  ApplicationClassLoader(String classpath, ClassLoader parent,
      List<String> systemClasses); }
ApplicationClassLoader extends URLClassLoader { @Override public URL getResource(String name) { URL url = null; if (!isSystemClass(name, systemClasses)) { url= findResource(name); if (url == null && name.startsWith("/")) { if (LOG.isDebugEnabled()) { LOG.debug("Remove leading / off " + name); } url= findResource(name.substring(1)); } } if (url == null) { url= parent.getResource(name); } if (url != null) { if (LOG.isDebugEnabled()) { LOG.debug("getResource("+name+")=" + url); } } return url; } ApplicationClassLoader(URL[] urls, ClassLoader parent,
      List<String> systemClasses);  ApplicationClassLoader(String classpath, ClassLoader parent,
      List<String> systemClasses); @Override URL getResource(String name); @Override Class<?> loadClass(String name); static boolean isSystemClass(String name, List<String> systemClasses); }
ApplicationClassLoader extends URLClassLoader { @Override public URL getResource(String name) { URL url = null; if (!isSystemClass(name, systemClasses)) { url= findResource(name); if (url == null && name.startsWith("/")) { if (LOG.isDebugEnabled()) { LOG.debug("Remove leading / off " + name); } url= findResource(name.substring(1)); } } if (url == null) { url= parent.getResource(name); } if (url != null) { if (LOG.isDebugEnabled()) { LOG.debug("getResource("+name+")=" + url); } } return url; } ApplicationClassLoader(URL[] urls, ClassLoader parent,
      List<String> systemClasses);  ApplicationClassLoader(String classpath, ClassLoader parent,
      List<String> systemClasses); @Override URL getResource(String name); @Override Class<?> loadClass(String name); static boolean isSystemClass(String name, List<String> systemClasses); static final String DEFAULT_SYSTEM_CLASSES; }