Example usage for java.lang ClassNotFoundException ClassNotFoundException

List of usage examples for java.lang ClassNotFoundException ClassNotFoundException

Introduction

In this page you can find the example usage for java.lang ClassNotFoundException ClassNotFoundException.

Prototype

public ClassNotFoundException(String s) 

Source Link

Document

Constructs a ClassNotFoundException with the specified detail message.

Usage

From source file:org.structr.StructrClassLoader.java

@Override
public Class<?> loadClass(String name) throws ClassNotFoundException {

    if (StringUtils.startsWith(name, "org.structr.dynamic")) {
        throw new ClassNotFoundException(name);
    }/*ww w  .  j  a  v a2s. c om*/

    return super.loadClass(name);
}

From source file:eu.stratosphere.nephele.util.ClassUtils.java

/**
 * Searches for a protocol class by its name and attempts to load it.
 * //from  w  w  w.  j av a  2  s.com
 * @param className
 *        the name of the protocol class
 * @return an instance of the protocol class
 * @throws ClassNotFoundException
 *         thrown if no class with such a name can be found
 */
// TODO: See if we can improve type safety here
@SuppressWarnings("unchecked")
public static Class<? extends VersionedProtocol> getProtocolByName(final String className)
        throws ClassNotFoundException {

    if (!className.contains("Protocol")) {
        throw new ClassNotFoundException("Only use this method for protocols!");
    }

    return (Class<? extends VersionedProtocol>) Class.forName(className, true, getClassLoader());
}

From source file:com.google.code.ddom.commons.cl.TransformingClassLoader.java

@Override
protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
    Class<?> clazz = findLoadedClass(name);
    if (clazz == null) {
        if (needsTransformation(name)) {
            String resourceName = ClassLoaderUtils.getResourceNameForClassName(name);
            InputStream in = super.getResourceAsStream(resourceName);
            if (in == null) {
                throw new ClassNotFoundException(name);
            }/*from   ww w  .  j a va 2 s.  c om*/
            try {
                try {
                    byte[] classDef = transformClass(name, IOUtils.toByteArray(in));
                    clazz = defineClass(name, classDef, 0, classDef.length);
                } finally {
                    in.close();
                }
            } catch (IOException ex) {
                throw new ClassNotFoundException(name, ex);
            }
        } else {
            clazz = super.loadClass(name, false);
        }
    }
    if (resolve) {
        resolveClass(clazz);
    }
    return clazz;
}

From source file:org.structr.StructrClassLoader.java

@Override
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {

    if (StringUtils.startsWith(name, "org.structr.dynamic")) {
        throw new ClassNotFoundException(name);
    }//  w  w  w .  j av a2 s.c  om

    return super.loadClass(name, resolve);
}

From source file:org.siyapath.task.TaskClassLoader.java

/**
 *
 * @param byteArray The bytes that make up the class data.
 * @param name class name/*from  w ww  .ja  va  2s.c o m*/
 * @return Class instance specified by byteArray and binary name of the class sent
 * @throws ClassNotFoundException
 */
public Class loadClassToProcess(byte[] byteArray, String name) throws ClassNotFoundException {

    Class loadingClass = defineClass(name, byteArray, 0, byteArray.length);
    if (loadingClass == null) {
        throw new ClassNotFoundException("Error in loading " + name);
    }
    resolveClass(loadingClass);
    log.info("Successfully loaded class " + name);

    return loadingClass;
}

From source file:org.raspinloop.fmi.VMRunnerUtils.java

public static String getWeaverAgentArgument(Collection<File> jars, boolean escaped)
        throws URISyntaxException, ClassNotFoundException, IOException {

    Path agentPath = filterJarContainingClass(jars, "org.aspectj.weaver.Constants");
    if (agentPath == null)
        throw new ClassNotFoundException("No jar found with class named org.aspectj.weaver.Constants");
    if (escaped)//from   w w  w . j  a v  a  2 s.c  om
        return toEscapedCliString(agentPath, "");
    else
        return toCliString(agentPath, "");
}

From source file:com.jsqlboxdemo.dispatcher.Dispatcher.java

public static void dispach(PageContext pageContext) throws Exception {
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    String uri = StringUtils.substringBefore(request.getRequestURI(), ".");
    String contextPath = request.getContextPath();

    if (!StringUtils.isEmpty(contextPath))
        uri = StringUtils.substringAfter(uri, contextPath);
    if (StringUtils.isEmpty(uri) || "/".equals(uri))
        uri = "/home";

    String[] paths = StringUtils.split(uri, "/");
    String[] pathParams;/*w  ww  .j  av  a 2 s . c om*/
    String resource = null;
    String operation = null;

    if (paths.length >= 2) {// /team/add/100...
        resource = paths[0];
        operation = paths[1];
        pathParams = new String[paths.length - 2];
        for (int i = 2; i < paths.length; i++)
            pathParams[i - 2] = paths[i];
    } else { // /home_default
        resource = paths[0];
        pathParams = new String[0];
    }

    if (operation == null)
        operation = "default";
    StringBuilder controller = new StringBuilder("com.jsqlboxdemo.controller.").append(resource).append("$")
            .append(resource).append("_").append(operation);
    if ("POST".equals(request.getMethod()))
        controller.append("_post");

    WebBox box;
    try {
        Class boxClass = Class.forName(controller.toString());
        box = BeanBox.getPrototypeBean(boxClass);
    } catch (Exception e) {
        throw new ClassNotFoundException("There is no WebBox classs '" + controller + "' found.");
    }
    request.setAttribute("pathParams", pathParams);
    box.show(pageContext);
}

From source file:com.cloudera.dataflow.hadoop.WritableCoder.java

@JsonCreator
@SuppressWarnings("unchecked")
public static WritableCoder<?> of(@JsonProperty("type") String classType) throws ClassNotFoundException {
    Class<?> clazz = Class.forName(classType);
    if (!Writable.class.isAssignableFrom(clazz)) {
        throw new ClassNotFoundException("Class " + classType + " does not implement Writable");
    }// w  w  w.ja  v a2 s.  c o  m
    return of((Class<? extends Writable>) clazz);
}

From source file:Main.java

public static List<Class<?>> getClassesForPackage(final String iPackageName, final ClassLoader iClassLoader)
        throws ClassNotFoundException {
    // This will hold a list of directories matching the pckgname.
    // There may be more than one if a package is split over multiple jars/paths
    List<Class<?>> classes = new ArrayList<Class<?>>();
    ArrayList<File> directories = new ArrayList<File>();
    try {/*from w ww  .j ava 2s. c  o m*/
        // Ask for all resources for the path
        final String packageUrl = iPackageName.replace('.', '/');
        Enumeration<URL> resources = iClassLoader.getResources(packageUrl);
        if (!resources.hasMoreElements()) {
            resources = iClassLoader.getResources(packageUrl + CLASS_EXTENSION);
            if (resources.hasMoreElements()) {
                throw new IllegalArgumentException(
                        iPackageName + " does not appear to be a valid package but a class");
            }
        } else {
            while (resources.hasMoreElements()) {
                URL res = resources.nextElement();
                if (res.getProtocol().equalsIgnoreCase("jar")) {
                    JarURLConnection conn = (JarURLConnection) res.openConnection();
                    JarFile jar = conn.getJarFile();
                    for (JarEntry e : Collections.list(jar.entries())) {

                        if (e.getName().startsWith(iPackageName.replace('.', '/'))
                                && e.getName().endsWith(CLASS_EXTENSION) && !e.getName().contains("$")) {
                            String className = e.getName().replace("/", ".").substring(0,
                                    e.getName().length() - 6);
                            classes.add(Class.forName(className));
                        }
                    }
                } else
                    directories.add(new File(URLDecoder.decode(res.getPath(), "UTF-8")));
            }
        }
    } catch (NullPointerException x) {
        throw new ClassNotFoundException(
                iPackageName + " does not appear to be " + "a valid package (Null pointer exception)");
    } catch (UnsupportedEncodingException encex) {
        throw new ClassNotFoundException(
                iPackageName + " does not appear to be " + "a valid package (Unsupported encoding)");
    } catch (IOException ioex) {
        throw new ClassNotFoundException(
                "IOException was thrown when trying " + "to get all resources for " + iPackageName);
    }

    // For every directory identified capture all the .class files
    for (File directory : directories) {
        if (directory.exists()) {
            // Get the list of the files contained in the package
            File[] files = directory.listFiles();
            for (File file : files) {
                if (file.isDirectory()) {
                    classes.addAll(findClasses(file, iPackageName));
                } else {
                    String className;
                    if (file.getName().endsWith(CLASS_EXTENSION)) {
                        className = file.getName().substring(0,
                                file.getName().length() - CLASS_EXTENSION.length());
                        classes.add(Class.forName(iPackageName + '.' + className));
                    }
                }
            }
        } else {
            throw new ClassNotFoundException(
                    iPackageName + " (" + directory.getPath() + ") does not appear to be a valid package");
        }
    }
    return classes;
}

From source file:SelfClassLoader.java

private byte[] loadClassBytes(String className) throws ClassNotFoundException {
    try {/* ww w  .  j  a  va 2 s. co m*/
        String classFile = getClassFile(className);
        FileInputStream fis = new FileInputStream(classFile);
        FileChannel fileC = fis.getChannel();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        WritableByteChannel outC = Channels.newChannel(baos);
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        while (true) {
            int i = fileC.read(buffer);
            if (i == 0 || i == -1) {
                break;
            }
            buffer.flip();
            outC.write(buffer);
            buffer.clear();
        }
        fis.close();
        return baos.toByteArray();
    } catch (IOException fnfe) {
        throw new ClassNotFoundException(className);
    }
}