static Collection<URL> getClassLoaderUrls() { final ClassLoader classLoader = PluginManagerCore.class.getClassLoader(); final Class<? extends ClassLoader> aClass = classLoader.getClass(); try { @SuppressWarnings("unchecked") List<URL> urls = (List<URL>) aClass.getMethod("getUrls").invoke(classLoader); return urls; } catch (IllegalAccessException ignored) { } catch (InvocationTargetException ignored) { } catch (NoSuchMethodException ignored) { } if (classLoader instanceof URLClassLoader) { return Arrays.asList(((URLClassLoader) classLoader).getURLs()); } return Collections.emptyList(); }
@SuppressWarnings({"HardCodedStringLiteral"}) static Method getAddUrlMethod(final ClassLoader loader) throws NoSuchMethodException { if (loader instanceof URLClassLoader) { final Method addUrlMethod = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); addUrlMethod.setAccessible(true); return addUrlMethod; } return loader.getClass().getDeclaredMethod("addURL", URL.class); }