List of usage examples for java.lang ClassLoader loadClass
public Class<?> loadClass(String name) throws ClassNotFoundException
From source file:com.wavemaker.commons.util.utils.ClassLoaderUtilsTest.java
@Test public void getClassLoaderTest() throws ClassNotFoundException { ClassLoader loader = ClassLoaderUtils.getClassLoader(); Class aClass = loader.loadClass("com.wavemaker.commons.util.utils.Car"); assertNotNull(aClass);//from ww w .java 2 s . c o m assertEquals(aClass, Car.class); }
From source file:com.googlecode.psiprobe.tools.logging.log4j.Log4JManagerAccessor.java
public Log4JManagerAccessor(ClassLoader cl) throws ClassNotFoundException { Class clazz = cl.loadClass("org.apache.log4j.LogManager"); Method m = MethodUtils.getAccessibleMethod(clazz, "exists", new Class[] { String.class }); if (m == null) { throw new RuntimeException("The LogManager is part of the slf4j bridge."); }//w w w.jav a 2 s. c o m setTarget(clazz); }
From source file:ClassVersionInfo.java
public ClassVersionInfo(String name, ClassLoader loader) throws ClassNotFoundException { this.name = name; Class c = loader.loadClass(name); CodeSource cs = c.getProtectionDomain().getCodeSource(); if (cs != null) location = cs.getLocation();//from w w w . j av a 2 s . c o m if (c.isInterface() == false) { ObjectStreamClass osc = ObjectStreamClass.lookup(c); if (osc != null) { serialVersion = osc.getSerialVersionUID(); try { c.getDeclaredField("serialVersionUID"); hasExplicitSerialVersionUID = true; } catch (NoSuchFieldException e) { hasExplicitSerialVersionUID = false; } } } }
From source file:de.xirp.plugin.PluginLoader.java
/** * Checks if the given plugin needs other plugins to run. * /*from w w w .j a va 2s.co m*/ * @param plugin * plugin to check * @param jarList * list of jar files on the class path * @param loader * the current class loader used to check if a class is * available * @return <code>true</code> if all other Plugins needed by this * Plugin are available * @see IPlugable#requiredLibs() */ @SuppressWarnings("unchecked") private static boolean checkNeeds(IPlugable plugin, ClassLoader loader, List<String> jarList) { if (plugin == null) { return true; } List<String> req = plugin.requiredLibs(); if (req == null) { return true; } boolean ret = true; for (String claas : req) { if (claas.endsWith(".jar")) { //$NON-NLS-1$ if (!jarList.contains(claas)) { ret &= false; logClass.warn(I18n.getString("PluginLoader.log.removingPluginBecauseOfMissingLib", //$NON-NLS-1$ plugin.getName(), claas) + Constants.LINE_SEPARATOR); } } else if (!currentPluginList.contains(claas)) { boolean hasClass = true; try { loader.loadClass(claas); } catch (ClassNotFoundException e) { logClass.error("Error: " + e.getMessage() + Constants.LINE_SEPARATOR, e); //$NON-NLS-1$ hasClass = false; } if (!hasClass) { logClass.warn(I18n.getString("PluginLoader.log.removingPluginBecauseOfMissingLib", //$NON-NLS-1$ plugin.getName(), claas) + Constants.LINE_SEPARATOR); ret &= false; break; } } else { refs.put(claas, plugin.getInfo().getMainClass()); } } return ret; }
From source file:net.contextfw.web.application.internal.classloading.ReloadingClassLoaderTest.java
@Test(expected = ClassNotFoundException.class) public void Throw_Class_CastException() throws ClassNotFoundException { conf = conf.add(/* w ww. j ava2s.c o m*/ RELOADABLE_CLASSES.includedPackage("net.contextfw.web.application.internal.classloading", false)) .add(RELOADABLE_CLASSES.excludedClass(NonReloadable.class)); ClassLoaderProvider provider = new ClassLoaderProvider(new ReloadingClassLoaderConf(conf)); ClassLoader classLoader = provider.reload(); classLoader.loadClass("net.contextfw.web.application.internal.classloading.Reloadaple"); }
From source file:org.eclipse.gemini.blueprint.test.internal.holder.HolderLoader.java
public HolderLoader() { // try to load the holder using the app ClassLoader ClassLoader appCL = Bundle.class.getClassLoader(); Class<?> clazz;/*from w ww .j ava 2 s . co m*/ try { clazz = appCL.loadClass(HOLDER_CLASS_NAME); } catch (Exception ex) { // if it's not found, then the class path is incorrectly constructed throw (RuntimeException) new IllegalStateException( "spring-osgi-test.jar is not available on the boot class path; are you deploying the test framework" + "as a bundle by any chance? ").initCause(ex); } // get the static instance Field field = ReflectionUtils.findField(clazz, INSTANCE_FIELD, clazz); Object instance; try { instance = field.get(null); } catch (Exception ex) { throw (RuntimeException) new IllegalStateException("Cannot read property " + INSTANCE_FIELD) .initCause(ex); } // once the class is loaded return it wrapped through it's OSGi instance holder = new ReflectionOsgiHolder(instance); }
From source file:com.autentia.tnt.validator.ValidatorFactory.java
private Validator getValidator(String className) { Class classFinal = null;//from ww w . ja v a 2s. c o m Validator validator = null; try { if (tableValidators.containsKey(className)) { classFinal = (Class) tableValidators.get(className); } else { ClassLoader cl = Thread.currentThread().getContextClassLoader(); classFinal = cl.loadClass(className); tableValidators.put(className, classFinal); } validator = (Validator) classFinal.newInstance(); } catch (Exception ex) { log.error("Error creating Validator: " + ex.getMessage()); } return validator; }
From source file:com.opensymphony.webwork.util.classloader.stores.ResourceStoreClassLoader.java
protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException { Class clazz = findLoadedClass(name); if (clazz == null) { clazz = fastFindClass(name);/* w w w. j a va 2 s.c om*/ if (clazz == null) { final ClassLoader parent = getParent(); if (parent != null) { clazz = parent.loadClass(name); log.debug("loaded from parent: " + name); } else { throw new ClassNotFoundException(name); } } else { log.debug("loaded from store: " + name); } } if (resolve) { resolveClass(clazz); } return clazz; }
From source file:com.hs.mail.container.simple.SimpleSpringContainer.java
public Object createFileSystemXmlApplicationContext(String[] configLocations) throws Exception { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Class klass = classLoader.loadClass(IMPL_CLASS_NAME); Object[] args = new Object[] { configLocations, Boolean.FALSE }; Object applicationContext = ConstructorUtils.invokeConstructor(klass, args); MethodUtils.invokeMethod(applicationContext, "refresh", null); return applicationContext; }
From source file:com.googlecode.jsonschema2pojo.integration.ant.Jsonschema2PojoTaskIT.java
@Test public void antTaskExecutesSuccessfullyWithValidSchemas() throws URISyntaxException, ClassNotFoundException { File outputDirectory = invokeAntBuild("/ant/build.xml"); ClassLoader resultsClassLoader = compile(outputDirectory, buildCustomClasspath()); Class<?> generatedClass = resultsClassLoader.loadClass("com.example.WordDelimit"); assertThat(generatedClass, is(notNullValue())); }