List of usage examples for java.lang ClassNotFoundException ClassNotFoundException
public ClassNotFoundException(String s)
ClassNotFoundException
with the specified detail message. From source file:org.bimserver.plugins.classloaders.EclipsePluginClassloader.java
@Override public Class<?> findClass(String name) throws ClassNotFoundException { String filename = name.replace(".", File.separator) + ".class"; if (loadedClasses.containsKey(filename)) { return loadedClasses.get(filename); }// w ww.j a v a2 s. c om Path classFile = classFolder.resolve(filename); if (Files.exists(classFile)) { try { byte[] bytes = IOUtils.toByteArray(Files.newInputStream(classFile)); Class<?> definedClass = defineClass(name, bytes, 0, bytes.length); if (definedClass != null) { loadedClasses.put(filename, definedClass); /* * This is a fix to actually load the package-info.class file with * the annotations about for example namespaces required for JAXB to * work. Found this code here: * https://issues.jboss.org/browse/JBPM-1404 */ if (definedClass != null) { final int packageIndex = name.lastIndexOf('.'); if (packageIndex != -1) { final String packageName = name.substring(0, packageIndex); final Package classPackage = getPackage(packageName); if (classPackage == null) { definePackage(packageName, null, null, null, null, null, null, null); } } } return definedClass; } } catch (IOException e) { LOGGER.error("", e); } } throw new ClassNotFoundException(name); }
From source file:oqube.bytes.loading.InstrumentingClassLoader.java
@Override protected Class<?> findClass(String name) throws ClassNotFoundException { String cln = name.replace('.', '/'); // lookup in loaded classes Class<?> cls = generated.get(cln); if (cls != null) return cls; else//w w w.j a v a 2 s.co m throw new ClassNotFoundException("Cannot find class " + name); }
From source file:com.thoughtworks.go.util.NestedJarClassLoader.java
@Override protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { if (existsInTfsJar(name)) { throw new ClassNotFoundException(name); }/*from w w w . j a va 2 s .c o m*/ return invokeParentClassloader(name, resolve); }
From source file:org.mule.providers.soap.axis.wsdl.wsrf.util.AdviceAdderHelper.java
/** * list Classes inside a given package.// w w w . ja v a 2 s. c om * * @param pckgname String name of a Package, EG "java.lang" * @return Class[] classes inside the root of the given package * @throws ClassNotFoundException if the Package is invalid */ private static Class[] getClasses(String pckgname) throws ClassNotFoundException { ArrayList classes = new ArrayList(); // Get a File object for the package File directory = null; try { URL str = Thread.currentThread().getContextClassLoader().getResource(pckgname.replace('.', '/')); System.out.println("instance advice..." + new File(str.getFile()).getName()); directory = new File(str.getFile()); } catch (NullPointerException x) { throw new ClassNotFoundException(pckgname + " does not appear to be a valid package"); } if (directory.exists()) { // Get the list of the files contained in the package String[] files = directory.list(); for (int i = 0; i < files.length; i++) { // we are only interested in *Advice.class files if (files[i].endsWith("Advice.class")) { // removes the .class extension classes.add(Class.forName( pckgname + '.' + files[i].substring(0, files[i].length() - SUFFIX_CLASS_LENGTH))); } } } else { throw new ClassNotFoundException(pckgname + " does not appear to be a valid package"); } Class[] classesA = new Class[classes.size()]; classes.toArray(classesA); return classesA; }
From source file:org.nuxeo.runtime.osgi.OSGiRuntimeActivator.java
public Class<?> loadClass(String bundleName, String className) throws ReflectiveOperationException { Bundle bundle = getBundle(bundleName); if (bundle == null) { throw new ClassNotFoundException( "No bundle found with name: " + bundleName + ". Unable to load class " + className); }/*from w ww.j a v a 2 s .c o m*/ return bundle.loadClass(className); }
From source file:org.grouplens.grapht.util.ClassProxy.java
/** * Resolve a class proxy to a class.// w w w. ja v a 2 s. c om * @return The class represented by this proxy. * @throws ClassNotFoundException if the class represented by this proxy cannot be found. */ public Class<?> resolve() throws ClassNotFoundException { WeakReference<Class<?>> ref = theClass; Class<?> cls = ref == null ? null : ref.get(); if (cls == null) { if (className.equals("void")) { // special case cls = Void.TYPE; } else { cls = ClassUtils.getClass(classLoader, className); } long check = checksumClass(cls); if (!isSerializationPermissive() && checksum != check) { throw new ClassNotFoundException("checksum mismatch for " + cls.getName()); } else { if (checksum != check) { logger.warn("checksum mismatch for {}", cls); } theClass = new WeakReference<Class<?>>(cls); } } return cls; }
From source file:org.ebayopensource.turmeric.eclipse.utils.classloader.SOAPluginClassLoader.java
/** * {@inheritDoc}/*from w ww . j a va 2 s . c o m*/ */ @Override protected Class<?> findClass(String name) throws ClassNotFoundException { Class<?> loadedClass = findLoadedClass(name); if (loadedClass != null) { return loadedClass; } StringBuilder sb = new StringBuilder(name.length() + 6); sb.append(name.replace('.', '/')).append(".class"); InputStream is = getResourceAsStream(sb.toString()); if (is == null) throw new ClassNotFoundException("Class not found " + sb); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; int len; while ((len = is.read(buf)) >= 0) baos.write(buf, 0, len); buf = baos.toByteArray(); // define package if not defined yet int i = name.lastIndexOf('.'); if (i != -1) { String pkgname = name.substring(0, i); Package pkg = getPackage(pkgname); if (pkg == null) definePackage(pkgname, null, null, null, null, null, null, null); } baos.close(); is.close(); return defineClass(name, buf, 0, buf.length); } catch (IOException e) { throw new ClassNotFoundException(name, e); } }
From source file:com.nttec.everychan.ui.theme.CustomThemeHelper.java
private View instantiate(String name, Context context, AttributeSet attrs) { try {/*from w ww .j a va 2 s.c om*/ Constructor<? extends View> constructor = CONSTRUCTOR_MAP.get(name); if (constructor == null) { Class<? extends View> clazz = null; if (name.indexOf('.') != -1) { clazz = context.getClassLoader().loadClass(name).asSubclass(View.class); } else { for (String prefix : CLASS_PREFIX_LIST) { try { clazz = context.getClassLoader().loadClass(prefix + name).asSubclass(View.class); break; } catch (ClassNotFoundException e) { } } if (clazz == null) throw new ClassNotFoundException("couldn't find class: " + name); } constructor = clazz.getConstructor(CONSTRUCTOR_SIGNATURE); CONSTRUCTOR_MAP.put(name, constructor); } Object[] args = constructorArgs; args[0] = context; args[1] = attrs; constructor.setAccessible(true); View view = constructor.newInstance(args); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && view instanceof ViewStub) CompatibilityImpl.setLayoutInflater((ViewStub) view, inflater.cloneInContext(context)); return view; } catch (Exception e) { Logger.e(TAG, "couldn't instantiate class " + name, e); return null; } }
From source file:org.cryptonode.jncryptor.JNCryptorFactory.java
/** * Retrieves an {@link JNCryptor} implementing the specified version number. * /* w ww. j a v a2s. c o m*/ * @param version * the version number. A positive number smaller than 256 (must be * expressible in eight bits). * @return the {@link JNCryptor} * @throws ClassNotFoundException * if no implementation exists for that version */ public static JNCryptor getCryptor(int version) throws ClassNotFoundException { JNCryptor cryptor = supportedVersions.get(version); if (cryptor == null) { throw new ClassNotFoundException(String.format("No implementation found for version %d.", version)); } return cryptor; }
From source file:org.apache.openejb.core.TempClassLoader.java
protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException { if (name == null) throw new NullPointerException("name cannot be null"); // see if we've already loaded it Class c = findLoadedClass(name); if (c != null) { return c; }//from w w w.j ava 2s . c o m // bug #283. defer to system if the name is a protected name. // "sun." is required for JDK 1.4, which has an access check for // sun.reflect.GeneratedSerializationConstructorAccessor1 /* * FIX for openejb-tomcat JSF support . Added the following to the if statement below: !name.startsWith("javax.faces") *We want to use this TempClassLoader to also load the classes in the javax.faces package. *If not, then our AnnotationDeployer will not be able to load the javax.faces.FacesServlet class if this class is in a jar which *is in the WEB-INF/lib directory of a web app. * see AnnotationDeployer$ProcessAnnotatedBeans.deploy(WebModule webModule) * Here is what happened before this fix was applied: * 1. The AnnotationDeployer tries to load the javax.faces.FacesServlet using this classloader (TempClassLoader) * 2. Since this class loader uses Class.forName to load classes starting with java, javax or sun, it cannot load javax.faces.FacesServlet * 3. Result is , AnnotationDeployer throws a ClassNotFoundException */ if (skip(name)) { return Class.forName(name, resolve, getClass().getClassLoader()); } // ( && !name.startsWith("javax.faces.") )|| String resourceName = name.replace('.', '/') + ".class"; InputStream in = getResourceAsStream(resourceName); if (in == null) { throw new ClassNotFoundException(name); } // 80% of class files are smaller then 6k ByteArrayOutputStream bout = new ByteArrayOutputStream(8 * 1024); // copy the input stream into a byte array byte[] bytes; try { byte[] buf = new byte[4 * 1024]; for (int count; (count = in.read(buf)) >= 0;) { bout.write(buf, 0, count); } bytes = bout.toByteArray(); } catch (IOException e) { throw new ClassNotFoundException(name, e); } // Annotation classes must be loaded by the normal classloader // So must Enum classes to prevent problems with the sun jdk. if (skip.contains(Skip.ANNOTATIONS) && isAnnotationClass(bytes)) { return Class.forName(name, resolve, getClass().getClassLoader()); } if (skip.contains(Skip.ENUMS) && isEnum(bytes)) { return Class.forName(name, resolve, getClass().getClassLoader()); } // define the package int packageEndIndex = name.lastIndexOf('.'); if (packageEndIndex != -1) { String packageName = name.substring(0, packageEndIndex); if (getPackage(packageName) == null) { definePackage(packageName, null, null, null, null, null, null, null); } } // define the class try { return defineClass(name, bytes, 0, bytes.length); } catch (SecurityException e) { // possible prohibited package: defer to the parent return super.loadClass(name, resolve); } catch (LinkageError le) { // fallback return super.loadClass(name, resolve); } }