List of usage examples for java.lang ClassNotFoundException ClassNotFoundException
public ClassNotFoundException(String s, Throwable ex)
ClassNotFoundException
with the specified detail message and optional exception that was raised while loading the class. From source file:org.apache.batchee.container.util.TCCLObjectInputStream.java
@Override protected Class resolveProxyClass(final String[] interfaces) throws IOException, ClassNotFoundException { final Class[] cinterfaces = new Class[interfaces.length]; for (int i = 0; i < interfaces.length; i++) { cinterfaces[i] = Class.forName(interfaces[i], false, tccl); }//from w ww . j a v a2 s . co m try { return Proxy.getProxyClass(tccl, cinterfaces); } catch (IllegalArgumentException e) { throw new ClassNotFoundException(null, e); } }
From source file:org.nuxeo.runtime.remoting.RemoteClassLoader.java
@Override protected Class<?> findClass(String name) throws ClassNotFoundException { Class klass = loadedClasses.get(name); if (klass != null) { return klass; }/*w w w .j a v a2 s .c o m*/ log.info("Loading class " + name + " from remote"); try { byte[] bytes = sd.getServer().getClass(component, name); if (bytes != null) { klass = defineClass(name, bytes, 0, bytes.length, null); loadedClasses.put(name, klass); return klass; } } catch (Exception e) { log.error("findClass failed", e); throw new ClassNotFoundException("Failed to find remote class", e); } return klass; }
From source file:com.acciente.commons.loader.JavaCompiledClassDef.java
private void loadCompiledClassFile() throws ClassNotFoundException { try {//ww w . j a v a2s.c om // checkpoint the compiled file's modified date before the compile long iLastModifiedTimeAtLastLoad = _oCompiledFile.lastModified(); _ayClassByteCode = FileUtils.readFileToByteArray(_oCompiledFile); _iLastModifiedTimeAtLastLoad = iLastModifiedTimeAtLastLoad; readReferencedClasses(_ayClassByteCode, _oCompiledFile.getName()); } catch (IOException e) { throw new ClassNotFoundException("Error loading class definition", e); } }
From source file:com.centurylink.mdw.common.translator.impl.JavaObjectTranslator.java
public Object realToObject(String str) throws TranslationException { ObjectInputStream ois = null; try {/*ww w.j av a 2 s. co m*/ byte[] decoded = decodeBase64(str); ByteArrayInputStream bais = new ByteArrayInputStream(decoded); ois = new ObjectInputStream(bais); try { return ois.readObject(); } catch (ClassNotFoundException ex) { ois.close(); bais = new ByteArrayInputStream(decoded); ois = new ObjectInputStream(bais) { @Override protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { try { return CompiledJavaCache.getResourceClass(desc.getName(), getClass().getClassLoader(), getPackage()); } catch (ClassNotFoundException ex) { if (getPackage() != null && getPackage().getCloudClassLoader() != null) return getPackage().getCloudClassLoader().loadClass(desc.getName()); else throw ex; } catch (MdwJavaException ex) { throw new ClassNotFoundException(desc.getName(), ex); } } }; return ois.readObject(); } } catch (Throwable t) { // including NoClassDefFoundError throw new TranslationException(t.getMessage(), t); } finally { if (ois != null) { try { ois.close(); } catch (IOException ex) { } } } }
From source file:org.eclipse.wb.internal.core.utils.external.ExternalFactoriesHelper.java
/** * @param className/*from w w w . j a v a 2 s. co m*/ * the name of {@link Class} to load. * * @return the {@link Class} loaded from this {@link ClassLoader} or from {@link Bundle} that * specifies that it can load class from some namespace. */ public static Class<?> loadBundleClass(String className) throws ClassNotFoundException { try { List<IConfigurationElement> contributors = getElements(CLASS_LOADING_CONTRIBUTORS, "contributor"); for (IConfigurationElement element : contributors) { String namespace = getRequiredAttribute(element, "namespace"); if (className.contains(namespace)) { try { return getExtensionBundle(element).loadClass(className); } catch (Throwable e) { } } } } catch (Throwable e) { throw new ClassNotFoundException("Exception during loading class " + className, e); } return Class.forName(className); }
From source file:ClassUtils.java
/** * Look up the class in the Tread Context ClassLoader and in the "current" ClassLoader. * @param className The class name to load * @param clazz a class used to get classloader * @return the corresponding Class instance * @throws ClassNotFoundException if the Class was not found. *//*from w ww . java 2 s . co m*/ public static Class forName(final String className, final Class clazz) throws ClassNotFoundException { // Load classes from different classloaders : // 1. Thread Context ClassLoader // 2. ClassUtils ClassLoader ClassLoader tccl = Thread.currentThread().getContextClassLoader(); Class cls = null; try { // Try with TCCL cls = Class.forName(className, true, tccl); } catch (ClassNotFoundException cnfe) { // Try now with the classloader used to load ClassUtils ClassLoader current = clazz.getClassLoader(); if (current != null) { try { cls = Class.forName(className, true, current); } catch (ClassNotFoundException cnfe2) { // If this is still unknown, throw an Exception throw new ClassNotFoundException("Class Not found in current ThreadClassLoader '" + tccl + "' and in '" + current + "' classloaders.", cnfe2); } } else { // rethrow exception throw cnfe; } } return cls; }
From source file:org.nebulaframework.deployment.classloading.node.exporter.GridNodeClassExporterImpl.java
/** * {@inheritDoc}//w w w. j a v a2s. c o m */ public byte[] exportClass(String name) throws ClassNotFoundException { try { // Build the physical class name String resName = "/" + name.replaceAll("\\.", "/") + ".class"; // Attempt to get the input stream for the class file InputStream is = Class.forName(name).getResourceAsStream(resName); if (is == null) { log.warn("[GridNodeClassExporter] InputStream NULL : " + resName); throw new IOException("Error retreiving InputStream for Class file, NULL"); } log.debug("[GridNodeClassExporter] Exporting " + name); return IOSupport.readBytes(is); } catch (IOException ex) { log.warn("Unable to export class due to IOException", ex); throw new ClassNotFoundException("Unable to export class due to IOException", ex); } catch (NullPointerException ex) { log.warn("Unable to locate class with in Node", ex); throw new ClassNotFoundException("Unable to locate class with in Node", ex); } }
From source file:org.beangle.model.persist.hibernate.internal.BundleDelegatingClassLoader.java
protected Class<?> findClass(String name) throws ClassNotFoundException { try {//from w w w. j a v a 2 s.c o m return this.backingBundle.loadClass(name); } catch (ClassNotFoundException cnfe) { // DebugUtils.debugClassLoading(backingBundle, name, null); throw new ClassNotFoundException( name + " not found from bundle [" + backingBundle.getSymbolicName() + "]", cnfe); } catch (NoClassDefFoundError ncdfe) { // This is almost always an error // This is caused by a dependent class failure, // so make sure we search for the right one. String cname = ncdfe.getMessage().replace('/', '.'); // DebugUtils.debugClassLoading(backingBundle, cname, name); NoClassDefFoundError e = new NoClassDefFoundError( cname + " not found from bundle [" + backingBundle + "]"); e.initCause(ncdfe); throw e; } }
From source file:oqube.bytes.loading.InstrumentingClassLoader.java
public Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { String cln = name.replace('.', '/'); // lookup in loaded classes Class<?> cls = generated.get(cln); if (cls != null) return cls; // instrument if include/exclude if (include.matcher(name).matches() && !exclude.matcher(name).matches()) { try {//from w w w .j a va 2s. com // lookup in factory classfiles ClassFile cf = factory.getGenerated().get(cln); // if not found, instrument it if (cf == null) cf = instrument(cln); // get bytes from class file ByteArrayOutputStream bos = new ByteArrayOutputStream(); cf.write(new DataOutputStream(bos)); byte[] bytes = bos.toByteArray(); cls = defineClass(name, bytes, 0, bytes.length); generated.put(cln, cls); if (resolve) resolveClass(cls); if (log.isInfoEnabled()) log.info("Done instrumenting " + cln); save(name, bytes); return cls; } catch (IOException e) { throw new ClassNotFoundException("Error while loading class to instrument " + name, e); } } else { return getParent().loadClass(name); } }
From source file:org.apache.openejb.client.EjbObjectInputStream.java
@Override protected Class resolveProxyClass(final String[] interfaces) throws IOException, ClassNotFoundException { final Class[] cinterfaces = new Class[interfaces.length]; for (int i = 0; i < interfaces.length; i++) { cinterfaces[i] = getClassloader().loadClass(interfaces[i]); }/*from w w w . j ava 2s. c om*/ try { return Proxy.getProxyClass(getClassloader(), cinterfaces); } catch (IllegalArgumentException e) { throw new ClassNotFoundException(null, e); } }