ClassPathUtils { public static URL getRuntimeClassLocation(String className) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); URL location = null; if (classLoader != null) { if (ClassLoaderUtils.isLoadedClass(classLoader, className)) { try { location = getRuntimeClassLocation(classLoader.loadClass(className)); } catch (ClassNotFoundException ignored) { } } } return location; }  @Nonnull static Set<String> getBootstrapClassPaths(); @Nonnull static Set<String> getClassPaths(); static URL getRuntimeClassLocation(String className); static URL getRuntimeClassLocation(Class<?> type);  }
@Test public void getRuntimeClassLocation() { URL location = null; location = ClassPathUtils.getRuntimeClassLocation(String.class); Assert.assertNotNull(location); echo(location); location = ClassPathUtils.getRuntimeClassLocation(getClass()); Assert.assertNotNull(location); echo(location); location = ClassPathUtils.getRuntimeClassLocation(int.class); Assert.assertNull(location); location = ClassPathUtils.getRuntimeClassLocation(int[].class); Assert.assertNull(location); Set<String> classNames = ClassUtils.getAllClassNamesInClassPaths(); for (String className : classNames) { if (!ClassLoaderUtils.isLoadedClass(classLoader, className)) { location = ClassPathUtils.getRuntimeClassLocation(className); Assert.assertNull(location); } } }