List of usage examples for java.lang ClassLoader loadClass
public Class<?> loadClass(String name) throws ClassNotFoundException
From source file:cz.lbenda.common.ClassLoaderHelper.java
public static <T> Class<T> getClassFromLibs(String className, List<String> libs, boolean useSystemClassPath) throws ClassNotFoundException { ClassLoader clr = createClassLoader(libs, useSystemClassPath); //noinspection unchecked return (Class<T>) clr.loadClass(className); }
From source file:com.googlecode.jsonschema2pojo.integration.FormatIT.java
@BeforeClass public static void generateClasses() throws ClassNotFoundException, IOException { ClassLoader resultsClassLoader = generateAndCompile("/schema/format/formattedProperties.json", "com.example"); classWithFormattedProperties = resultsClassLoader.loadClass("com.example.FormattedProperties"); }
From source file:corner.protobuf.ProtocolBuffersModule.java
private static void addProtobufferCoercer(MappedConfiguration<Class, ValueEncoderFactory> configuration, ClassLoader contextClassLoader, String className) { try {/*w w w .j av a 2 s.c o m*/ Class protoClass = contextClassLoader.loadClass(className); //?classProtocolBuffer?? if (ProtocolBuffer.class.isAssignableFrom(protoClass)) { final ValueEncoderFactory factory = new ValueEncoderFactory() { /** * @see org.apache.tapestry5.services.ValueEncoderFactory#create(java.lang.Class) */ @Override @SuppressWarnings("unchecked") public ValueEncoder create(Class type) { return new ProtoValueEncoder(type); } }; configuration.add(protoClass, factory); } } catch (ClassNotFoundException ex) { throw new RuntimeException(ex); } }
From source file:com.dotosoft.dot4command.impl.CatalogFactoryBase.java
/** * Check to see if we have an implementation of a valid configuration * parsing class loaded at runtime. If not, we throw an * IllegalStateException./* w w w . j av a 2 s . com*/ */ public static void checkForValidConfigurationModule() { try { ClassLoader cl = getClassLoader(); cl.loadClass("com.dotosoft.dot4command.chain.config.ConfigParser"); } catch (ClassNotFoundException e) { String msg = "Couldn't not find a configuration implementation. " + "Load a chain configuration module such as xml-configuration " + "into the classpath and try again."; throw new IllegalStateException(msg, e); } }
From source file:Main.java
public static boolean overrideClassLoader(ClassLoader cl, File dex, File opt) { try {//w w w . j av a 2 s .c o m ClassLoader bootstrap = cl.getParent(); Field fPathList = BaseDexClassLoader.class.getDeclaredField("pathList"); fPathList.setAccessible(true); Object pathList = fPathList.get(cl); Class cDexPathList = bootstrap.loadClass("dalvik.system.DexPathList"); Field fDexElements = cDexPathList.getDeclaredField("dexElements"); fDexElements.setAccessible(true); Object dexElements = fDexElements.get(pathList); DexClassLoader cl2 = new DexClassLoader(dex.getAbsolutePath(), opt.getAbsolutePath(), null, bootstrap); Object pathList2 = fPathList.get(cl2); Object dexElements2 = fDexElements.get(pathList2); Object element2 = Array.get(dexElements2, 0); int n = Array.getLength(dexElements) + 1; Object newDexElements = Array.newInstance(fDexElements.getType().getComponentType(), n); Array.set(newDexElements, 0, element2); for (int i = 0; i < n - 1; i++) { Object element = Array.get(dexElements, i); Array.set(newDexElements, i + 1, element); } fDexElements.set(pathList, newDexElements); return true; } catch (Exception e) { Log.e("lcast", "fail to override classloader " + cl + " with " + dex, e); return false; } }
From source file:hudson.lifecycle.Lifecycle.java
/** * Gets the singleton instance./*from w w w. j a v a 2s .c o m*/ * * @return never null */ public synchronized static Lifecycle get() { if (INSTANCE == null) { String p = System.getProperty("hudson.lifecycle"); if (p != null) { try { ClassLoader cl = Hudson.getInstance().getPluginManager().uberClassLoader; INSTANCE = (Lifecycle) cl.loadClass(p).newInstance(); } catch (InstantiationException e) { InstantiationError x = new InstantiationError(e.getMessage()); x.initCause(e); throw x; } catch (IllegalAccessException e) { IllegalAccessError x = new IllegalAccessError(e.getMessage()); x.initCause(e); throw x; } catch (ClassNotFoundException e) { NoClassDefFoundError x = new NoClassDefFoundError(e.getMessage()); x.initCause(e); throw x; } } else { // if run on Unix, we can do restart if (!Hudson.isWindows()) { try { INSTANCE = new UnixLifecycle(); } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to install embedded lifecycle implementation", e); } } // use the default one. final fallback. if (INSTANCE == null) INSTANCE = new Lifecycle() { }; } } return INSTANCE; }
From source file:org.jsonschema2pojo.integration.FormatIT.java
@BeforeClass public static void generateClasses() throws ClassNotFoundException, IOException { ClassLoader resultsClassLoader = classSchemaRule .generateAndCompile("/schema/format/formattedProperties.json", "com.example"); classWithFormattedProperties = resultsClassLoader.loadClass("com.example.FormattedProperties"); }
From source file:com.google.gdt.eclipse.designer.smart.parser.ClassLoaderValidator.java
/** * @return the description of invalid version, or <code>null</code> if version in valid. *///from w w w . j a v a 2s.co m private static String getWrongVersionDescription(final ClassLoader classLoader) { return ExecutionUtils.runObject(new RunnableObjectEx<String>() { public String runObject() throws Exception { Class<?> classVersion = classLoader.loadClass("com.smartgwt.client.Version"); String version = (String) ReflectionUtils.invokeMethod(classVersion, "getVersion()"); if (ArrayUtils.contains(VALID_VERSIONS, version)) { initializeSmartGWT(classLoader); return null; } return version; } }, "See logged exception"); }
From source file:gov.nih.nci.ncicb.cadsr.common.util.ObjectFactory.java
/** * Load a class for the specified name and scope. * In the cases when the active ClassLoader is null, we use * Class.forName(), otherwise ClassLoader.loadClass() is used *///w w w.j av a2s . c o m public static Class forName(Class scope, String className) throws ClassNotFoundException { ClassLoader loader = null; try { loader = Thread.currentThread().getContextClassLoader(); } // end try catch (Exception e) { loader = scope.getClassLoader(); } // end catch return (loader != null) ? loader.loadClass(className) : Class.forName(className); }
From source file:info.novatec.testit.livingdoc.util.ClassUtils.java
public static Class<?> loadClass(ClassLoader classLoader, String className) throws ClassNotFoundException { return classLoader.loadClass(className); }