use of java.net.URLClassLoader in project zeppelin by apache.
the class InterpreterSettingManager method registerInterpreterFromResource.
private boolean registerInterpreterFromResource(ClassLoader cl, String interpreterDir, String interpreterJson) throws IOException, RepositoryException {
URL[] urls = recursiveBuildLibList(new File(interpreterDir));
ClassLoader tempClassLoader = new URLClassLoader(urls, cl);
Enumeration<URL> interpreterSettings = tempClassLoader.getResources(interpreterJson);
if (!interpreterSettings.hasMoreElements()) {
return false;
}
for (URL url : Collections.list(interpreterSettings)) {
try (InputStream inputStream = url.openStream()) {
logger.debug("Reading {} from {}", interpreterJson, url);
List<RegisteredInterpreter> registeredInterpreterList = getInterpreterListFromJson(inputStream);
registerInterpreters(registeredInterpreterList, interpreterDir);
}
}
return true;
}
use of java.net.URLClassLoader in project zeppelin by apache.
the class InterpreterFactory method createRepl.
private Interpreter createRepl(String dirName, String className, Properties property) throws InterpreterException {
logger.info("Create repl {} from {}", className, dirName);
ClassLoader oldcl = Thread.currentThread().getContextClassLoader();
try {
URLClassLoader ccl = cleanCl.get(dirName);
if (ccl == null) {
// classloader fallback
ccl = URLClassLoader.newInstance(new URL[] {}, oldcl);
}
boolean separateCL = true;
try {
// check if server's classloader has driver already.
Class cls = this.getClass().forName(className);
if (cls != null) {
separateCL = false;
}
} catch (Exception e) {
logger.error("exception checking server classloader driver", e);
}
URLClassLoader cl;
if (separateCL == true) {
cl = URLClassLoader.newInstance(new URL[] {}, ccl);
} else {
cl = ccl;
}
Thread.currentThread().setContextClassLoader(cl);
Class<Interpreter> replClass = (Class<Interpreter>) cl.loadClass(className);
Constructor<Interpreter> constructor = replClass.getConstructor(new Class[] { Properties.class });
Interpreter repl = constructor.newInstance(property);
repl.setClassloaderUrls(ccl.getURLs());
LazyOpenInterpreter intp = new LazyOpenInterpreter(new ClassloaderInterpreter(repl, cl));
return intp;
} catch (SecurityException e) {
throw new InterpreterException(e);
} catch (NoSuchMethodException e) {
throw new InterpreterException(e);
} catch (IllegalArgumentException e) {
throw new InterpreterException(e);
} catch (InstantiationException e) {
throw new InterpreterException(e);
} catch (IllegalAccessException e) {
throw new InterpreterException(e);
} catch (InvocationTargetException e) {
throw new InterpreterException(e);
} catch (ClassNotFoundException e) {
throw new InterpreterException(e);
} finally {
Thread.currentThread().setContextClassLoader(oldcl);
}
}
use of java.net.URLClassLoader in project hive by apache.
the class TestClassNameCompleter method addingEmptyFile.
@Test
public void addingEmptyFile() throws IOException {
String fileName = "empty.file";
File p = tmpFolder.newFile(fileName);
URLClassLoader classLoader = (URLClassLoader) Thread.currentThread().getContextClassLoader();
try {
URLClassLoader newClassLoader = new URLClassLoader(new URL[] { p.toURL() }, classLoader);
Thread.currentThread().setContextClassLoader(newClassLoader);
ClassNameCompleter.getClassNames();
} finally {
Thread.currentThread().setContextClassLoader(classLoader);
}
}
use of java.net.URLClassLoader in project buck by facebook.
the class FileClassPathRunner method main.
public static void main(String[] args) throws IOException, ReflectiveOperationException {
// We must have the name of the class to delegate to added.
if (args.length < 1) {
System.exit(-1);
}
ClassLoader sysLoader = ClassLoader.getSystemClassLoader();
if (!(sysLoader instanceof URLClassLoader)) {
System.exit(-2);
}
URLClassLoader urlClassLoader = (URLClassLoader) sysLoader;
modifyClassLoader(urlClassLoader, true);
// Now read the main class from the args and invoke it
Method main = getMainClass(args);
String[] mainArgs = constructArgs(args);
main.invoke(null, new Object[] { mainArgs });
}
use of java.net.URLClassLoader in project hibernate-orm by hibernate.
the class HibernatePlugin method toClassLoader.
private ClassLoader toClassLoader(FileCollection runtimeClasspath) {
List<URL> urls = new ArrayList<URL>();
for (File file : runtimeClasspath) {
try {
urls.add(file.toURI().toURL());
logger.debug("Adding classpath entry for " + file.getAbsolutePath());
} catch (MalformedURLException e) {
throw new GradleException("Unable to resolve classpath entry to URL : " + file.getAbsolutePath(), e);
}
}
return new URLClassLoader(urls.toArray(new URL[urls.size()]), Enhancer.class.getClassLoader());
}
Aggregations