use of java.net.URLClassLoader in project L42 by ElvisResearchGroup.
the class L42 method setClassPath.
private static void setClassPath(Path p) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
assert Files.isDirectory(p);
List<URL> fileNames = new ArrayList<>();
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(p)) {
for (Path path : directoryStream) {
fileNames.add(path.toUri().toURL());
}
} catch (IOException ex) {
Assertions.codeNotReachable("" + ex);
}
//System.out.println(fileNames);
L42.pluginPaths = fileNames;
URLClassLoader loader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Method method = URLClassLoader.class.getDeclaredMethod("addURL", new Class[] { URL.class });
method.setAccessible(true);
for (URL url : fileNames) {
method.invoke(loader, new Object[] { url });
}
}
use of java.net.URLClassLoader in project jdk8u_jdk by JetBrains.
the class NIOCharsetAvailabilityTest method addCharsets.
private static void addCharsets(Set charsets, final String packageName) throws Exception {
String classPath = (String) java.security.AccessController.doPrivileged(new sun.security.action.GetPropertyAction("sun.boot.class.path"));
String s = (String) java.security.AccessController.doPrivileged(new sun.security.action.GetPropertyAction("java.class.path"));
// Search combined system and application class path
if (s != null && s.length() != 0) {
classPath += File.pathSeparator + s;
}
while (classPath != null && classPath.length() != 0) {
int i = classPath.lastIndexOf(java.io.File.pathSeparatorChar);
String dir = classPath.substring(i + 1);
if (i == -1) {
classPath = null;
} else {
classPath = classPath.substring(0, i);
}
classPathSegments.insertElementAt(dir, 0);
}
// add extensions from the extension class loader
ClassLoader appLoader = Launcher.getLauncher().getClassLoader();
URLClassLoader extLoader = (URLClassLoader) appLoader.getParent();
URL[] urls = extLoader.getURLs();
for (int i = 0; i < urls.length; i++) {
try {
URI uri = new URI(urls[i].toString());
classPathSegments.insertElementAt(uri.getPath(), 0);
} catch (URISyntaxException e) {
}
}
String[] classList = (String[]) java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {
public Object run() {
return getClassList(packageName, "");
}
});
for (int i = 0; i < classList.length; i++) {
try {
Class clazz = Class.forName(packageName + "." + classList[i]);
Class superclazz = clazz.getSuperclass();
while (superclazz != null && !superclazz.equals(Object.class)) {
if (superclazz.equals(Charset.class)) {
charsets.add(clazz);
break;
} else {
superclazz = superclazz.getSuperclass();
}
}
} catch (ClassNotFoundException e) {
}
}
}
use of java.net.URLClassLoader in project opentsdb by OpenTSDB.
the class PluginLoader method addURL.
/**
* Attempts to add the given file/URL to the class loader
* @param url Full path to the file to add
* @throws SecurityException if there is a security manager present and the
* operation is denied
* @throws IllegalArgumentException if the path was not a directory
* @throws NoSuchMethodException if there is an error with the class loader
* @throws IllegalAccessException if a security manager is present and the
* operation was denied
* @throws InvocationTargetException if there is an issue loading the jar
*/
private static void addURL(final URL url) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Class<?> sysclass = URLClassLoader.class;
Method method = sysclass.getDeclaredMethod("addURL", PARAMETER_TYPES);
method.setAccessible(true);
method.invoke(sysloader, new Object[] { url });
LOG.debug("Successfully added JAR to class loader: " + url.getFile());
}
use of java.net.URLClassLoader in project intellij-community by JetBrains.
the class PluginDescriptorTest method testFilteringDuplicates.
@Test
public void testFilteringDuplicates() throws MalformedURLException {
URL[] urls = { new File(getTestDataPath(), "duplicate1.jar").toURI().toURL(), new File(getTestDataPath(), "duplicate2.jar").toURI().toURL() };
assertEquals(1, PluginManagerCore.testLoadDescriptorsFromClassPath(new URLClassLoader(urls, null)).size());
}
use of java.net.URLClassLoader in project intellij-community by JetBrains.
the class RemoteAgentClassLoaderCache method getOrCreateClassLoader.
public URLClassLoader getOrCreateClassLoader(Set<URL> libraryUrls) {
URLClassLoader result = myUrls2ClassLoader.get(libraryUrls);
if (result == null) {
result = new URLClassLoader(libraryUrls.toArray(new URL[libraryUrls.size()]), null);
myUrls2ClassLoader.put(libraryUrls, result);
}
return result;
}
Aggregations