/** * @since Ant 1.6.2 */ private boolean isTomcat5x() { try (AntClassLoader l = getProject().createClassLoader(getClasspath())) { l.loadClass("org.apache.jasper.tagplugins.jstl.If"); return true; } catch (ClassNotFoundException e) { return false; } } }
return loader.loadClass(classname);
/** * Load named class and test whether it can be rmic'ed * @param classname the name of the class to be tested * @return true if the class can be rmic'ed */ public boolean isValidRmiRemote(String classname) { try { Class<?> testClass = loader.loadClass(classname); // One cannot RMIC an interface for "classic" RMI (JRMP) return (!testClass.isInterface() || iiop || idl) && isValidRmiRemote(testClass); } catch (ClassNotFoundException e) { log(ERROR_UNABLE_TO_VERIFY_CLASS + classname + ERROR_NOT_FOUND, Project.MSG_WARN); } catch (NoClassDefFoundError e) { log(ERROR_UNABLE_TO_VERIFY_CLASS + classname + ERROR_NOT_DEFINED, Project.MSG_WARN); } catch (Throwable t) { log(ERROR_UNABLE_TO_VERIFY_CLASS + classname + ERROR_LOADING_CAUSED_EXCEPTION + t.getMessage(), Project.MSG_WARN); } // we only get here if an exception has been thrown return false; }
@Override protected synchronized Class<?> loadClass(String classname, boolean resolve) throws ClassNotFoundException { Class<?> theClass = findLoadedClass(classname); if (theClass != null) { return theClass; } if (isSplit(classname)) { theClass = findClass(classname); if (resolve) { resolveClass(theClass); } return theClass; } return super.loadClass(classname, resolve); }
loader.loadClass(classname); } else { ClassLoader l = this.getClass().getClassLoader();
dc = loader.loadClass(driver).asSubclass(Driver.class); } else { log("Loading " + driver + " using system loader.",
cl.loadClass(JonasDeploymentTool.GENIC_CLASS); log("Found GenIC class '" + JonasDeploymentTool.GENIC_CLASS + "' in classpath.", Project.MSG_VERBOSE); cl.loadClass(JonasDeploymentTool.OLD_GENIC_CLASS_1); log("Found GenIC class '" + JonasDeploymentTool.OLD_GENIC_CLASS_1 cl.loadClass(JonasDeploymentTool.OLD_GENIC_CLASS_2); log("Found GenIC class '" + JonasDeploymentTool.OLD_GENIC_CLASS_2
/** * Checks is a junit is on given path. * @param path the {@link Path} to check * @return true when given {@link Path} contains junit * @since 1.9.8 */ private boolean hasJunit(final Path path) { try (AntClassLoader loader = AntClassLoader.newAntClassLoader( null, getProject(), path, true)) { try { loader.loadClass("junit.framework.Test"); return true; } catch (final Exception ex) { return false; } } }
public void testGetResource_precache() throws Exception { Callable<String,IOException> c = (Callable<String,IOException>)cl.loadClass("test.HelloGetResource").newInstance(); String v = channel.call(c); System.out.println(v); verifyResourcePrecache(v); }
public void testInnerClass() throws Exception { Echo<Object> e = new Echo<Object>(); e.value = cl.loadClass("test.Foo").newInstance(); Object r = channel.call(e); ((Predicate)r).apply(null); // this verifies that the object is still in a good state }
dc = loader.loadClass(driver); } else { log("Loading " + driver + " using system loader.", Project.MSG_VERBOSE);
public void testGetResourceAsStream() throws Exception { Callable<String,IOException> c = (Callable<String,IOException>)cl.loadClass("test.HelloGetResourceAsStream").newInstance(); String v = channel.call(c); assertEquals("hello",v); }
/** * Unlike {@link #testGetResources()}, the URL should begin with file:... before the jar file gets cached */ public void testGetResources_precache() throws Exception { Callable<String,IOException> c = (Callable<String,IOException>)cl.loadClass("test.HelloGetResources").newInstance(); String v = channel.call(c); System.out.println(v); // should find two resources String[] lines = v.split("\n"); assertTrue(lines[0], lines[0].startsWith("file:")); assertTrue(lines[1], lines[1].startsWith("file:")); assertTrue(lines[0], lines[0].endsWith("::hello")); assertTrue(lines[1], lines[1].endsWith("::hello2")); }
@SuppressWarnings("rawtypes") @Override protected synchronized Class loadClass(String classname, boolean resolve) throws ClassNotFoundException { // 'sync' is needed - otherwise 2 threads can load the same class // twice, resulting in LinkageError: duplicated class definition. // findLoadedClass avoids that, but without sync it won't work. Class theClass = findLoadedClass(classname); if (theClass != null) { return theClass; } if (!forked) { // KTH changed try { theClass = realm.loadClass(classname); log("Class " + classname + " loaded from class realm " , Project.MSG_DEBUG); } catch (ClassNotFoundException cnfe) { theClass = findClass(classname); } } else { theClass = super.loadClass(classname, resolve); } return theClass; } }
Class clazz = classloader.loadClass( class_file ); logMsgIfVerbose( I18N_LOADED_CLASS, clazz );
public void testGetResource() throws Exception { channel.call(new ForceJarLoad(sum1)); channel.call(new ForceJarLoad(sum2)); Callable<String,IOException> c = (Callable<String,IOException>)cl.loadClass("test.HelloGetResource").newInstance(); String v = channel.call(c); System.out.println(v); verifyResource(v); }
/** * This should cause the jar file to be sent to the other side */ public void testJarLoadingTest() throws Exception { channel.call(new ForceJarLoad(sum1)); channel.call(new ForceJarLoad(sum2)); Callable<Void,IOException> sc = (Callable)cl.loadClass("test.ClassLoadingFromJarTester").newInstance(); ((Function)sc).apply(new Verifier()); assertNull(channel.call(sc)); }
/** * Once the jar files are cached, ClassLoader.getResources() should return jar URLs. */ public void testGetResources() throws Exception { channel.call(new ForceJarLoad(sum1)); channel.call(new ForceJarLoad(sum2)); Callable<String,IOException> c = (Callable<String,IOException>)cl.loadClass("test.HelloGetResources").newInstance(); String v = channel.call(c); System.out.println(v); // should find two resources String[] lines = v.split("\n"); verifyResource(lines[0]); Assert.assertThat(lines[1], allOf(startsWith("jar:file:"), containsString(dir.toURI().getPath()), endsWith("::hello2"))); }