本文整理了Java中java.net.URLClassLoader.getParent()
方法的一些代码示例,展示了URLClassLoader.getParent()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。URLClassLoader.getParent()
方法的具体详情如下:
包路径:java.net.URLClassLoader
类名称:URLClassLoader
方法名:getParent
暂无
代码示例来源:origin: org.glassfish.main.web/war-util
@Override
public URLClassLoader run() {
return new URLClassLoader(urlArray, webAppCl.getParent());
}
});
代码示例来源:origin: zhong-j-yu/bayou
ClassLoaderFactory(URLClassLoader launcherClassLoader)
{
this.parentCL = launcherClassLoader.getParent(); // could be null.
this.allUrls.addAll(Arrays.asList(launcherClassLoader.getURLs()));
}
代码示例来源:origin: GeeQuery/ef-orm
/**
* 得到虚拟机扩展的ClassLoader
*/
public static URLClassLoader getJvmExtClassLoader() {
return (URLClassLoader) getAppClassLoader().getParent();
}
代码示例来源:origin: org.ow2.frascati/frascati-assembly-factory
/**
* Debug output for given ClassLoader - print loaded URLs
*
* @param classLoader ClassLoader used
*/
protected final void debug(ClassLoader classLoader, PrintStream printStream)
{
ClassLoader cl = (classLoader != null) ? classLoader : this.mainClassLoader;
PrintStream out = (printStream != null) ? printStream : System.err;
out.println("----- Debugging ClassLoader ----------");
out.println("List of URL loaded for ClassLoader : " + cl);
out.println("--------------------------------------");
while (cl instanceof URLClassLoader) {
URLClassLoader urlcl = (URLClassLoader) cl;
for (URL url : urlcl.getURLs()) {
out.println("> " + url);
}
cl = urlcl.getParent();
}
out.println("--------------------------------------");
}
代码示例来源:origin: apache/twill
/**
* Creates a {@link ClassLoader} to be used by this container that load classes from the given classpath.
*/
private static ClassLoader createContainerClassLoader(URL[] classpath) {
String containerClassLoaderName = System.getProperty(Constants.TWILL_CONTAINER_CLASSLOADER);
URLClassLoader classLoader = new URLClassLoader(classpath);
if (containerClassLoaderName == null) {
return classLoader;
}
try {
@SuppressWarnings("unchecked")
Class<? extends ClassLoader> cls = (Class<? extends ClassLoader>) classLoader.loadClass(containerClassLoaderName);
// Instantiate with constructor (URL[] classpath, ClassLoader parentClassLoader)
return cls.getConstructor(URL[].class, ClassLoader.class).newInstance(classpath, classLoader.getParent());
} catch (ClassNotFoundException e) {
throw new RuntimeException("Failed to load container class loader class " + containerClassLoaderName, e);
} catch (NoSuchMethodException e) {
throw new RuntimeException("Container class loader must have a public constructor with " +
"parameters (URL[] classpath, ClassLoader parent)", e);
} catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
throw new RuntimeException("Failed to create container class loader of class " + containerClassLoaderName, e);
}
}
代码示例来源:origin: cdapio/cdap
/**
* Creates a {@link ClassLoader} to be used by this container that load classes from the given classpath.
*/
private static ClassLoader createContainerClassLoader(URL[] classpath) {
String containerClassLoaderName = System.getProperty(Constants.TWILL_CONTAINER_CLASSLOADER);
URLClassLoader classLoader = new URLClassLoader(classpath);
if (containerClassLoaderName == null) {
return classLoader;
}
try {
@SuppressWarnings("unchecked")
Class<? extends ClassLoader> cls = (Class<? extends ClassLoader>) classLoader.loadClass(containerClassLoaderName);
// Instantiate with constructor (URL[] classpath, ClassLoader parentClassLoader)
return cls.getConstructor(URL[].class, ClassLoader.class).newInstance(classpath, classLoader.getParent());
} catch (ClassNotFoundException e) {
throw new RuntimeException("Failed to load container class loader class " + containerClassLoaderName, e);
} catch (NoSuchMethodException e) {
throw new RuntimeException("Container class loader must have a public constructor with " +
"parameters (URL[] classpath, ClassLoader parent)", e);
} catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
throw new RuntimeException("Failed to create container class loader of class " + containerClassLoaderName, e);
}
}
代码示例来源:origin: org.apache.twill/twill-core
/**
* Creates a {@link ClassLoader} to be used by this container that load classes from the given classpath.
*/
private static ClassLoader createContainerClassLoader(URL[] classpath) {
String containerClassLoaderName = System.getProperty(Constants.TWILL_CONTAINER_CLASSLOADER);
URLClassLoader classLoader = new URLClassLoader(classpath);
if (containerClassLoaderName == null) {
return classLoader;
}
try {
@SuppressWarnings("unchecked")
Class<? extends ClassLoader> cls = (Class<? extends ClassLoader>) classLoader.loadClass(containerClassLoaderName);
// Instantiate with constructor (URL[] classpath, ClassLoader parentClassLoader)
return cls.getConstructor(URL[].class, ClassLoader.class).newInstance(classpath, classLoader.getParent());
} catch (ClassNotFoundException e) {
throw new RuntimeException("Failed to load container class loader class " + containerClassLoaderName, e);
} catch (NoSuchMethodException e) {
throw new RuntimeException("Container class loader must have a public constructor with " +
"parameters (URL[] classpath, ClassLoader parent)", e);
} catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
throw new RuntimeException("Failed to create container class loader of class " + containerClassLoaderName, e);
}
}
代码示例来源:origin: co.cask.cdap/cdap-app-fabric
/**
* Creates a {@link ClassLoader} to be used by this container that load classes from the given classpath.
*/
private static ClassLoader createContainerClassLoader(URL[] classpath) {
String containerClassLoaderName = System.getProperty(Constants.TWILL_CONTAINER_CLASSLOADER);
URLClassLoader classLoader = new URLClassLoader(classpath);
if (containerClassLoaderName == null) {
return classLoader;
}
try {
@SuppressWarnings("unchecked")
Class<? extends ClassLoader> cls = (Class<? extends ClassLoader>) classLoader.loadClass(containerClassLoaderName);
// Instantiate with constructor (URL[] classpath, ClassLoader parentClassLoader)
return cls.getConstructor(URL[].class, ClassLoader.class).newInstance(classpath, classLoader.getParent());
} catch (ClassNotFoundException e) {
throw new RuntimeException("Failed to load container class loader class " + containerClassLoaderName, e);
} catch (NoSuchMethodException e) {
throw new RuntimeException("Container class loader must have a public constructor with " +
"parameters (URL[] classpath, ClassLoader parent)", e);
} catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
throw new RuntimeException("Failed to create container class loader of class " + containerClassLoaderName, e);
}
}
代码示例来源:origin: gridkit/nanocloud
public static Collection<URL> listCurrentClasspath(URLClassLoader classLoader) {
Set<URL> result = new LinkedHashSet<URL>();
while(true) {
for(URL url: classLoader.getURLs()) {
addEntriesFromManifest(result, url);
}
ClassLoader cls = classLoader.getParent();
if (cls instanceof URLClassLoader) {
if (cls.getClass().getName().endsWith("$ExtClassLoader")) {
break;
}
classLoader = (URLClassLoader) cls;
}
else {
break;
}
}
return new ArrayList<URL>(result);
}
代码示例来源:origin: org.dspace.dependencies.solr/dspace-solr-core
private static URLClassLoader replaceClassLoader(final URLClassLoader oldLoader,
final File base,
final FileFilter filter) {
if (null != base && base.canRead() && base.isDirectory()) {
File[] files = base.listFiles(filter);
if (null == files || 0 == files.length) return oldLoader;
URL[] oldElements = oldLoader.getURLs();
URL[] elements = new URL[oldElements.length + files.length];
System.arraycopy(oldElements, 0, elements, 0, oldElements.length);
for (int j = 0; j < files.length; j++) {
try {
URL element = files[j].toURI().normalize().toURL();
log.info("Adding '" + element.toString() + "' to classloader");
elements[oldElements.length + j] = element;
} catch (MalformedURLException e) {
SolrException.log(log, "Can't add element to classloader: " + files[j], e);
}
}
return URLClassLoader.newInstance(elements, oldLoader.getParent());
}
// are we still here?
return oldLoader;
}
代码示例来源:origin: org.apache.geronimo.modules/geronimo-jaxws-builder
public static void getClassLoaderClasspath(ClassLoader loader, LinkedHashSet<URL> classpath) {
if (loader == null || loader == ClassLoader.getSystemClassLoader()) {
return;
// } else if (loader instanceof MultiParentClassLoader) {
// MultiParentClassLoader cl = (MultiParentClassLoader)loader;
// for (ClassLoader parent : cl.getParents()) {
// getClassLoaderClasspath(parent, classpath);
// }
// for (URL u : cl.getURLs()) {
// classpath.add(u);
// }
} else if (loader instanceof URLClassLoader) {
URLClassLoader cl = (URLClassLoader)loader;
getClassLoaderClasspath(cl.getParent(), classpath);
for (URL u : cl.getURLs()) {
classpath.add(u);
}
} else {
getClassLoaderClasspath(loader.getParent(), classpath);
}
}
代码示例来源:origin: com.googlecode.fighting-layout-bugs/fighting-layout-bugs
/**
* Constructs the class path of the {@link Thread#getContextClassLoader() current class loader}.
*/
public ClassPath() {
List<File> files = new ArrayList<File>();
URLClassLoader classLoader = (URLClassLoader) Thread.currentThread().getContextClassLoader();
do {
URL[] urls = classLoader.getURLs();
if (urls.length == 1 && "sun.misc.Launcher$AppClassLoader".equals(classLoader.getClass().getName())) {
File jarFile = toFile(urls[0]);
files.add(jarFile);
files.addAll(readClassPathFromManifestOf(jarFile));
} else {
for (URL url : urls) {
File file = toFile(url);
files.add(file);
if (SUREFIREBOOTER_JAR_FILE_NAME_PATTERN.matcher(file.getName()).matches()) {
files.addAll(readClassPathFromManifestOf(file));
}
}
}
ClassLoader parentClassLoader = classLoader.getParent();
// noinspection ObjectEquality
classLoader = (parentClassLoader instanceof URLClassLoader && parentClassLoader != classLoader ? (URLClassLoader) parentClassLoader : null);
} while (classLoader != null);
_files = Collections.unmodifiableList(files);
}
代码示例来源:origin: org.robolectric/robolectric-sandbox
public SandboxClassLoader(URLClassLoader systemClassLoader, InstrumentationConfiguration config, URL... urls) {
super(systemClassLoader.getURLs(), systemClassLoader.getParent());
this.systemClassLoader = systemClassLoader;
this.config = config;
this.urls = new URLClassLoader(urls, null);
classesToRemap = convertToSlashes(config.classNameTranslations());
methodsToIntercept = convertToSlashes(config.methodsToIntercept());
for (URL url : urls) {
Logger.debug("Loading classes from: %s", url);
}
}
代码示例来源:origin: 8tory/SimpleWeibo
/**
* Make a different ClassLoader that loads the same URLs as this one, and use it to compile
* an {@code @RetroWeibo} class. If Velocity loads its managers using the context class loader,
* and that loader is still the original one that loaded this test, then it will find the
* original copy of the Velocity classes rather than the one from the new loader, and fail.
*
* <p>This test assumes that the test class was loaded by a URLClassLoader and that that loader's
* URLs also include the Velocity classes.
*/
public void testClassLoaderHack() throws Exception {
URLClassLoader myLoader = (URLClassLoader) getClass().getClassLoader();
URLClassLoader newLoader = new URLClassLoader(myLoader.getURLs(), myLoader.getParent());
String velocityClassName = Velocity.class.getName();
Class<?> myVelocity = myLoader.loadClass(velocityClassName);
Class<?> newVelocity = newLoader.loadClass(velocityClassName);
assertThat(myVelocity).isNotEqualTo(newVelocity);
Runnable test = (Runnable) newLoader.loadClass(RunInClassLoader.class.getName()).newInstance();
assertThat(test.getClass()).isNotEqualTo(RunInClassLoader.class);
test.run();
}
代码示例来源:origin: javapathfinder/jpf-core
@Test
public void testConstructorEmptyURLs () {
if (verifyNoPropertyViolation()) {
URLClassLoader cl = new URLClassLoader(new URL[0]);
assertNotNull(cl.getParent());
assertEquals(cl.getParent(), ClassLoader.getSystemClassLoader());
}
}
代码示例来源:origin: yongjhih/AutoJson
/**
* Make a different ClassLoader that loads the same URLs as this one, and use it to compile
* an {@code @AutoJson} class. If Velocity loads its managers using the context class loader,
* and that loader is still the original one that loaded this test, then it will find the
* original copy of the Velocity classes rather than the one from the new loader, and fail.
*
* <p>This test assumes that the test class was loaded by a URLClassLoader and that that loader's
* URLs also include the Velocity classes.
*/
public void testClassLoaderHack() throws Exception {
URLClassLoader myLoader = (URLClassLoader) getClass().getClassLoader();
URLClassLoader newLoader = new URLClassLoader(myLoader.getURLs(), myLoader.getParent());
String velocityClassName = Velocity.class.getName();
Class<?> myVelocity = myLoader.loadClass(velocityClassName);
Class<?> newVelocity = newLoader.loadClass(velocityClassName);
assertThat(myVelocity).isNotEqualTo(newVelocity);
Runnable test = (Runnable) newLoader.loadClass(RunInClassLoader.class.getName()).newInstance();
assertThat(test.getClass()).isNotEqualTo(RunInClassLoader.class);
test.run();
}
代码示例来源:origin: yongjhih/RetroFacebook
/**
* Make a different ClassLoader that loads the same URLs as this one, and use it to compile
* an {@code @RetroFacebook} class. If Velocity loads its managers using the context class loader,
* and that loader is still the original one that loaded this test, then it will find the
* original copy of the Velocity classes rather than the one from the new loader, and fail.
*
* <p>This test assumes that the test class was loaded by a URLClassLoader and that that loader's
* URLs also include the Velocity classes.
*/
public void testClassLoaderHack() throws Exception {
URLClassLoader myLoader = (URLClassLoader) getClass().getClassLoader();
URLClassLoader newLoader = new URLClassLoader(myLoader.getURLs(), myLoader.getParent());
String velocityClassName = Velocity.class.getName();
Class<?> myVelocity = myLoader.loadClass(velocityClassName);
Class<?> newVelocity = newLoader.loadClass(velocityClassName);
assertThat(myVelocity).isNotEqualTo(newVelocity);
Runnable test = (Runnable) newLoader.loadClass(RunInClassLoader.class.getName()).newInstance();
assertThat(test.getClass()).isNotEqualTo(RunInClassLoader.class);
test.run();
}
代码示例来源:origin: yongjhih/RetroFacebook
/**
* Make a different ClassLoader that loads the same URLs as this one, and use it to compile
* an {@code @RetroFacebook} class. If Velocity loads its managers using the context class loader,
* and that loader is still the original one that loaded this test, then it will find the
* original copy of the Velocity classes rather than the one from the new loader, and fail.
*
* <p>This test assumes that the test class was loaded by a URLClassLoader and that that loader's
* URLs also include the Velocity classes.
*/
public void testClassLoaderHack() throws Exception {
URLClassLoader myLoader = (URLClassLoader) getClass().getClassLoader();
URLClassLoader newLoader = new URLClassLoader(myLoader.getURLs(), myLoader.getParent());
String velocityClassName = Velocity.class.getName();
Class<?> myVelocity = myLoader.loadClass(velocityClassName);
Class<?> newVelocity = newLoader.loadClass(velocityClassName);
assertThat(myVelocity).isNotEqualTo(newVelocity);
Runnable test = (Runnable) newLoader.loadClass(RunInClassLoader.class.getName()).newInstance();
assertThat(test.getClass()).isNotEqualTo(RunInClassLoader.class);
test.run();
}
代码示例来源:origin: javapathfinder/jpf-core
@Test
public void testConstructorParent() {
if (verifyNoPropertyViolation()) {
URL[] urls = new URL[0];
ClassLoader parent = new TestClassLoader(urls);
URLClassLoader cl = new URLClassLoader(urls, parent);
assertNotNull(parent.getParent());
assertEquals(parent.getParent(), ClassLoader.getSystemClassLoader());
assertNotNull(cl.getParent());
assertEquals(cl.getParent(), parent);
}
}
代码示例来源:origin: javapathfinder/jpf-core
@Test
public void testNewInstance2() throws MalformedURLException, ClassNotFoundException {
movePkgOut();
if (verifyNoPropertyViolation()) {
URL[] urls = new URL[1];
urls[0] = new URL(dirUrl);
URLClassLoader parent = URLClassLoader.newInstance(urls);
URLClassLoader cl = URLClassLoader.newInstance(urls, parent);
assertSame(parent, cl.getParent());
Class<?> c = cl.loadClass(pkg + ".Class1");
assertNotNull(c);
assertSame(c.getClassLoader(), parent);
String resName = pkg + "/Interface1.class";
URL resource = cl.getResource(resName);
assertNotNull(resource);
resource = cl.getParent().getResource(resName);
assertNotNull(resource);
}
movePkgBack();
}
内容来源于网络,如有侵权,请联系作者删除!