List of usage examples for java.lang ClassLoader getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.opensymphony.xwork2.util.LocalizedTextUtil.java
private static void clearTomcatCache() { ClassLoader loader = Thread.currentThread().getContextClassLoader(); // no need for compilation here. Class cl = loader.getClass(); try {/*from ww w .j a v a 2s. c o m*/ if ("org.apache.catalina.loader.WebappClassLoader".equals(cl.getName())) { clearMap(cl, loader, "resourceEntries"); } else { if (LOG.isDebugEnabled()) { LOG.debug("class loader " + cl.getName() + " is not tomcat loader."); } } } catch (Exception e) { if (LOG.isWarnEnabled()) { LOG.warn("couldn't clear tomcat cache", e); } } }
From source file:ThreadDemo.java
public void run() { // returns the context ClassLoader for this Thread ClassLoader c = getContextClassLoader(); // sets the context ClassLoader for this Thread setContextClassLoader(c);//from w w w . ja v a 2 s . c om System.out.println("Class = " + c.getClass()); System.out.println("Parent = " + c.getParent()); }
From source file:Main.java
ThreadDemo() { Thread t = new Thread(this); t.start();//ww w . ja v a 2 s . com ClassLoader c = t.getContextClassLoader(); // sets the context ClassLoader for this Thread t.setContextClassLoader(c); System.out.println("Class = " + c.getClass()); System.out.println("Parent = " + c.getParent()); }
From source file:org.jboss.snowdrop.context.support.JBossJcaResourceAdapterParser.java
@Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { ClassLoader classLoader = getClass().getClassLoader(); if (classLoader.getClass().getName().startsWith("org.jboss.classloader")) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(); builder.getRawBeanDefinition().setFactoryBeanName(DEFAULT_JBOSS_MBEAN_SERVER_BEAN_NAME); builder.getRawBeanDefinition().setFactoryMethodName(FACTORY_METHOD_NAME); try {/*from www. j a va 2 s.co m*/ builder.addConstructorArgValue(ObjectName.getInstance(DEFAULT_JCA_MBEAN_NAME)); } catch (MalformedObjectNameException e) { throw new IllegalArgumentException(e); } builder.addConstructorArgValue("ResourceAdapter"); return builder.getBeanDefinition(); } else { BeanDefinitionBuilder builder = BeanDefinitionBuilder .rootBeanDefinition("org.jboss.snowdrop.context.support.ActivatorHolder"); builder.setFactoryMethod("getResourceAdapter"); return builder.getBeanDefinition(); } }
From source file:com.opensymphony.xwork2.util.DefaultLocalizedTextProvider.java
private static void clearTomcatCache() { ClassLoader loader = getCurrentThreadContextClassLoader(); // no need for compilation here. Class cl = loader.getClass(); try {//from w w w. j a va 2 s. co m if ("org.apache.catalina.loader.WebappClassLoader".equals(cl.getName())) { clearMap(cl, loader, TOMCAT_RESOURCE_ENTRIES_FIELD); } else { LOG.debug("Class loader {} is not tomcat loader.", cl.getName()); } } catch (NoSuchFieldException nsfe) { if ("org.apache.catalina.loader.WebappClassLoaderBase".equals(cl.getSuperclass().getName())) { LOG.debug("Base class {} doesn't contain '{}' field, trying with parent!", cl.getName(), TOMCAT_RESOURCE_ENTRIES_FIELD, nsfe); try { clearMap(cl.getSuperclass(), loader, TOMCAT_RESOURCE_ENTRIES_FIELD); } catch (Exception e) { LOG.warn("Couldn't clear tomcat cache using {}", cl.getSuperclass().getName(), e); } } } catch (Exception e) { LOG.warn("Couldn't clear tomcat cache", cl.getName(), e); } }
From source file:at.ac.tuwien.infosys.jcloudscale.test.unit.ClassLoaderTest.java
InputStream getInputStream(ClassLoader classLoader) { Method method = findMethod(classLoader.getClass(), "getRemoteResourceAsStream", (Class<?>[]) null); makeAccessible(method);/*from w w w. j ava 2s.c o m*/ return (InputStream) invokeMethod(method, classLoader, RESOURCE); }
From source file:com.thoughtworks.go.agent.common.util.ParentClassAccessFilteringClassloader.java
@Override protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { if (permittedParentDefns.length == 0) { return super.loadClass(name, false); }//from w w w . j a v a 2 s. com for (Class permittedParentDefn : permittedParentDefns) { if (permittedParentDefn.getCanonicalName().equals(name)) { ClassLoader parent = getParent(); LOG.info(String.format("Loading %s using %s", name, parent == null ? "null classloader" : parent.getClass().getCanonicalName())); return super.loadClass(name, false); } } return getSystemClassLoader().loadClass(name); }
From source file:at.ac.tuwien.infosys.jcloudscale.test.unit.ClassLoaderTest.java
@Test(timeout = TIMEOUT) public void testSystemClassLoader() throws Exception { SystemClassLoaderConfiguration classLoaderConfiguration = new SystemClassLoaderConfiguration(); startup(classLoaderConfiguration);/*w ww . j a va2 s . c o m*/ ClassLoader classLoader = classLoaderConfiguration.createClassLoader(); assertSame(ClassLoader.getSystemClassLoader().getClass(), classLoader.getClass()); InputStream stream = classLoader.getResourceAsStream(RESOURCE); assertNotNull(stream); assertEquals(CONTENT, IOUtils.toString(stream)); }
From source file:net.sf.nmedit.jtheme.JTContext.java
public void setUIDefaultsClassLoader(ClassLoader loader) { Log log = getLogger();//from w w w .j av a 2s . com if (log.isInfoEnabled()) { Class<?> loaderClass = loader == null ? null : loader.getClass(); log.info("Setting UIDefaults ClassLoader in " + this + ": " + loader + " (" + loaderClass + ")"); } getUIDefaults().put(UIDefaultsClassLoaderKey, loader); }
From source file:com.github.drochetti.javassist.maven.ClassTransformer.java
private void debugClassLoader(final ClassPool classPool) { if (!logger.isDebugEnabled()) { return;/*from w w w . j a v a 2 s .c o m*/ } logger.debug(" - classPool: " + classPool.toString()); ClassLoader classLoader = classPool.getClassLoader(); while (classLoader != null) { logger.debug(" -- " + classLoader.getClass().getName() + ": " + classLoader.toString()); if (classLoader instanceof URLClassLoader) { logger.debug(" --- urls: " + Arrays.deepToString(((URLClassLoader) classLoader).getURLs())); } classLoader = classLoader.getParent(); } }