public static void main(String[] args) throws MalformedURLException, ClassNotFoundException { Policy.setPolicy(new PluginSecurityPolicy()); System.setSecurityManager(new SecurityManager()); PluginClassLoader urlCL = new PluginClassLoader(new File( "A Jar containing images/load.gif and SampleApp class").toURL()); Class<?> loadClass = urlCL.loadClass("net.sourceforge.marathon.examples.SampleApp"); System.out.println(loadClass); System.out.println("Loading the class using the class loader object. Resource = " + urlCL.getResource("images/load.gif")); System.out.println("Loading the class using the class loader object with absolute path. Resource = " + urlCL.getResource("/images/load.gif")); System.out.println("Loading the class using the class object. Resource = " + loadClass.getResource("images/load.gif")); }
Class<?> class1 = classLoader.loadClass(classname); return (Class<T>) class1; } else {
Class<?> class1 = classLoader.loadClass(classname); return (Class<T>) class1; } else {
Class<?> class1 = classLoader.loadClass(classname); return (Class<T>) class1; } else {
Plugin plugin = pluginRegistry.loadPlugin(coordinates); PluginClassLoader classLoader = plugin.getLoader(); Class<?> class1 = classLoader.loadClass(classname); return createCustomComponent(componentType, class1, configProperties); } else {
@Override public void handle(IAsyncResult<Plugin> result) { if (result.isSuccess()) { IPolicy rval; Plugin plugin = result.getResult(); PluginClassLoader pluginClassLoader = plugin.getLoader(); ClassLoader oldCtxLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(pluginClassLoader); Class<?> c = pluginClassLoader.loadClass(classname); rval = (IPolicy) c.newInstance(); } catch (Exception e) { handler.handle(AsyncResultImpl.<IPolicy>create(new PolicyNotFoundException(policyImpl, e))); return; } finally { Thread.currentThread().setContextClassLoader(oldCtxLoader); } policyCache.put(policyImpl, rval); handler.handle(AsyncResultImpl.create(rval)); } else { handler.handle(AsyncResultImpl.<IPolicy>create(new PolicyNotFoundException(policyImpl, result.getError()))); } } });
@Override public void handle(IAsyncResult<Plugin> result) { if (result.isSuccess()) { IPolicy rval; Plugin plugin = result.getResult(); PluginClassLoader pluginClassLoader = plugin.getLoader(); ClassLoader oldCtxLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(pluginClassLoader); Class<?> c = pluginClassLoader.loadClass(classname); rval = (IPolicy) c.newInstance(); } catch (Exception e) { handler.handle(AsyncResultImpl.<IPolicy>create(new PolicyNotFoundException(policyImpl, e))); return; } finally { Thread.currentThread().setContextClassLoader(oldCtxLoader); } policyCache.put(policyImpl, rval); handler.handle(AsyncResultImpl.create(rval)); } else { handler.handle(AsyncResultImpl.<IPolicy>create(new PolicyNotFoundException(policyImpl, result.getError()))); } } });