ClassUtils { public static URL getCodeSourceLocation(Class<?> type) throws NullPointerException { URL codeSourceLocation = null; ClassLoader classLoader = type.getClassLoader(); if (classLoader == null) { String path = findClassPath(type); if (StringUtils.isNotBlank(path)) { try { codeSourceLocation = new File(path).toURI().toURL(); } catch (MalformedURLException ignored) { codeSourceLocation = null; } } } else { ProtectionDomain protectionDomain = type.getProtectionDomain(); CodeSource codeSource = protectionDomain == null ? null : protectionDomain.getCodeSource(); codeSourceLocation = codeSource == null ? null : codeSource.getLocation(); } return codeSourceLocation; } private  ClassUtils(); @Nonnull static Set<String> getAllPackageNamesInClassPaths(); @Nullable static String resolvePackageName(String className); @Nonnull static Set<String> findClassNamesInClassPath(String classPath, boolean recursive); @Nullable static String findClassPath(Class<?> type); @Nullable static String findClassPath(String className); @Nonnull static Set<String> getClassNamesInClassPath(String classPath, boolean recursive); @Nonnull static Set<String> getClassNamesInPackage(Package onePackage); @Nonnull static Set<String> getClassNamesInPackage(String packageName); static String resolveClassName(String resourceName); @Nonnull static Map<String, Set<String>> getClassPathToClassNamesMap(); @Nonnull static Set<String> getAllClassNamesInClassPaths(); static URL getCodeSourceLocation(Class<?> type);  }
@Test public void testGetCodeSourceLocation() throws IOException { URL codeSourceLocation = null; Assert.assertNull(codeSourceLocation); codeSourceLocation = ClassUtils.getCodeSourceLocation(ClassUtilsTest.class); echo("codeSourceLocation : " + codeSourceLocation); Assert.assertNotNull(codeSourceLocation); codeSourceLocation = ClassUtils.getCodeSourceLocation(String.class); echo("codeSourceLocation : " + codeSourceLocation); Assert.assertNotNull(codeSourceLocation); }