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.firstopen.singularity.devicemgr.emulators.EmulatorManager.java

/**
 * @param args// w ww .  java2s . c  om
 * @throws Exception 
 */
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {

    XMLConfiguration config;
    try {
        URL url = ClassLoader.getSystemResource("emulation.xml");

        config = new XMLConfiguration(url);

        Object obj = config.getProperty("emulatons.emulator.class");
        Collection<String> classes = null;
        if (obj instanceof Collection) {
            classes = (Collection<String>) obj;
        } else
            throw new ClassNotFoundException("property is not of type Collection");

        Thread[] threads = new Thread[50];
        int i = 0;
        for (String className : classes) {

            List<String> portList = (List<String>) config.getList("emulations.emulator(" + i + ").ports");
            Class c = Class.forName(className);

            log.info("Shutdown manager registered...");
            ShutdownManager sdm = new ShutdownManager();
            Runtime.getRuntime().addShutdownHook(sdm);

            Class partypes[] = new Class[1];
            partypes[0] = String.class;
            Constructor ct = c.getConstructor(partypes);
            for (String port : portList) {
                Object arglist[] = new Object[1];
                arglist[0] = new Integer(37);
                arglist[1] = new Integer(47);
                Object emulator = ct.newInstance(arglist);

                ShutdownManager.addManagedObject((Shutdown) emulator);
                threads[i] = new Thread((Runnable) emulator);
                threads[i].start();

            } // end for all ports

            i++;
        } // end for all emulators
        for (Thread thread : threads) {
            thread.join();
        }
    } catch (Exception e) {

        throw e;
    }
}

From source file:com.almende.eve.deploy.Boot.java

/**
 * The default agent booter. It takes an EVE yaml file and creates all
 * agents mentioned in the "agents" section.
 * //from  www.j a  va  2s. com
 * @param args
 *            Single argument: args[0] -> Eve yaml
 */
public static void main(final String[] args) {
    if (args.length == 0) {
        LOG.warning("Missing argument pointing to yaml file:");
        LOG.warning("Usage: java -jar <jarfile> eve.yaml");
        return;
    }
    final ClassLoader cl = new ClassLoader() {
        @Override
        protected Class<?> findClass(final String name) throws ClassNotFoundException {
            Class<?> result = null;
            try {
                result = super.findClass(name);
            } catch (ClassNotFoundException cne) {
            }
            if (result == null) {
                FileInputStream fi = null;
                try {

                    String path = name.replace('.', '/');
                    fi = new FileInputStream(System.getProperty("user.dir") + "/" + path + ".class");
                    byte[] classBytes = new byte[fi.available()];
                    fi.read(classBytes);
                    fi.close();
                    return defineClass(name, classBytes, 0, classBytes.length);
                } catch (Exception e) {
                    LOG.log(Level.WARNING, "Failed to load class:", e);
                }
            }
            if (result == null) {
                throw new ClassNotFoundException(name);
            }
            return result;
        }
    };
    String configFileName = args[0];
    try {
        InputStream is = new FileInputStream(new File(configFileName));
        boot(is, cl);

    } catch (FileNotFoundException e) {
        LOG.log(Level.WARNING, "Couldn't find configfile:" + configFileName, e);
        return;
    }

}

From source file:PlotDriver.java

/** Construct a Plotter driver, and try it out. */
public static void main(String[] argv) {
    Plotter r;//from  w  w w . j a v  a  2s.  c o m
    //      if (argv.length != 1) {
    //      System.err.println("Usage: PlotDriver driverclass");
    //   return;
    //      }
    try {
        Class c = Class.forName("PlotterAWT");
        Object o = c.newInstance();
        if (!(o instanceof Plotter))
            throw new ClassNotFoundException("Not instanceof Plotter");
        r = (Plotter) o;
    } catch (ClassNotFoundException e) {
        System.err.println("Sorry, " + argv[0] + " not a plotter class");
        return;
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }
    r.penDown();
    r.penColor(1);
    r.moveTo(200, 200);
    r.penColor(2);
    r.drawBox(123, 200);
    r.rmoveTo(10, 20);
    r.penColor(3);
    r.drawBox(123, 200);
    r.penUp();
    r.moveTo(300, 100);
    r.penDown();
    r.setFont("Helvetica", 14);
    r.drawString("Hello World");
    r.penColor(4);
    r.drawBox(10, 10);
}

From source file:Main.java

public static long JavaToUnoType(Object obj, long fallbackTypePtr, boolean typeHasFallbackClass)
        throws ClassNotFoundException {
    Class<?> firstCls = obj.getClass();
    Long unoTypePtr = unoTypes.get(firstCls.getName());
    if (unoTypePtr != null) {
        return (long) unoTypePtr;
    } else {//from   w  w  w . j  ava2s.com
        if (typeHasFallbackClass) {
            Class<?> itf = unoFallbacks.get(fallbackTypePtr);
            if (itf == null) {
                throw new ClassNotFoundException(
                        "BINDING CLASS NOT FOUND (unoFallbacks): Not found for unoTypePtr:" + fallbackTypePtr);
            }
            Class<?> currentCls = firstCls;
            while (true) {
                if ((!itf.equals(currentCls)) && itf.isAssignableFrom(currentCls)) {
                    Long potential = unoTypes.get(currentCls.getName());
                    if (potential != null) {
                        unoTypes.put(firstCls.getName(), potential);
                        return (long) potential;
                    }
                } else {
                    unoTypes.put(firstCls.getName(), fallbackTypePtr);
                    return fallbackTypePtr;
                }
                currentCls = currentCls.getSuperclass();
                if (currentCls == null) {
                    unoTypes.put(firstCls.getName(), fallbackTypePtr);
                    return fallbackTypePtr;
                }
            }
        } else {
            Class<?> currentCls = firstCls;
            while (true) {
                currentCls = currentCls.getSuperclass();
                if (currentCls == null) {
                    unoTypes.put(firstCls.getName(), fallbackTypePtr);
                    return fallbackTypePtr;
                } else {
                    Long potential = unoTypes.get(currentCls.getName());
                    if (potential != null) {
                        if (Modifier.isAbstract(currentCls.getModifiers())) {
                            Long fallbackClassPtr = unoFallbacksClassToPtr.get(currentCls);
                            if (fallbackClassPtr != null) {
                                unoTypes.put(firstCls.getName(), fallbackClassPtr);
                                return fallbackClassPtr;
                            }
                        } else {
                            unoTypes.put(firstCls.getName(), potential);
                            return (long) potential;
                        }
                    }
                }
            }
        }
    }
}

From source file:Utils.java

/**
 * This methods load a class given the classloader and the name of the class, and work for
 * extended names of primitive types. <p>
 * If you try to do ClassLoader.loadClass("boolean") it barfs it cannot find the class,
 * so this method cope with this problem.
 *//*from ww w .  jav a  2s .c  o m*/
public static Class loadClass(ClassLoader loader, String name) throws ClassNotFoundException {
    if (name == null)
        throw new ClassNotFoundException("null");

    name = name.trim();
    if (name.equals("boolean"))
        return boolean.class;
    else if (name.equals("byte"))
        return byte.class;
    else if (name.equals("char"))
        return char.class;
    else if (name.equals("short"))
        return short.class;
    else if (name.equals("int"))
        return int.class;
    else if (name.equals("long"))
        return long.class;
    else if (name.equals("float"))
        return float.class;
    else if (name.equals("double"))
        return double.class;
    else if (name.equals("java.lang.String"))
        return String.class;
    else if (name.equals("java.lang.Object"))
        return Object.class;
    else if (name.startsWith("[")) {
        // It's an array, figure out how many dimensions
        int dimension = 0;
        while (name.charAt(dimension) == '[') {
            ++dimension;
        }
        char type = name.charAt(dimension);
        Class cls = null;
        switch (type) {
        case 'Z':
            cls = boolean.class;
            break;
        case 'B':
            cls = byte.class;
            break;
        case 'C':
            cls = char.class;
            break;
        case 'S':
            cls = short.class;
            break;
        case 'I':
            cls = int.class;
            break;
        case 'J':
            cls = long.class;
            break;
        case 'F':
            cls = float.class;
            break;
        case 'D':
            cls = double.class;
            break;
        case 'L':
            // Strip the semicolon at the end
            String n = name.substring(dimension + 1, name.length() - 1);
            cls = loadClass(loader, n);
            break;
        }

        if (cls == null) {
            throw new ClassNotFoundException(name);
        } else {
            int[] dim = new int[dimension];
            return Array.newInstance(cls, dim).getClass();
        }
    } else {
        if (loader != null)
            return loader.loadClass(name);
        else
            return Class.forName(name, false, null);
    }
}

From source file:com.liferay.tool.datamanipulator.util.GetterUtil.java

public static Class<?> getClass(String... classNames) throws ClassNotFoundException {

    for (String className : classNames) {
        try {/*from   www .  jav  a  2 s .co m*/
            return getClass(className);
        } catch (ClassNotFoundException cnfe) {
        }
    }

    throw new ClassNotFoundException("Requested class not found: " + ArrayUtils.toString(classNames));
}

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

public static String getWeaverAgentArgument(String basePath, boolean escaped)
        throws URISyntaxException, ClassNotFoundException, IOException {

    Path agentPath = getJarContainingClass(basePath, "org.aspectj.weaver.Constants");
    if (agentPath == null)
        throw new ClassNotFoundException("No jar found with class named org.aspectj.weaver.Constants");
    if (escaped)//from  w ww.  ja  v a2s  .  c o m
        return toEscapedCliString(agentPath, "");
    else
        return toCliString(agentPath, "");
}

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

public static String getRunnerAgentArgument(String basePath, String jSonConfigName, boolean escaped)
        throws URISyntaxException, ClassNotFoundException, IOException {

    Path agentPath = getJarContainingClass(basePath, "org.raspinloop.agent.PreMain");
    if (agentPath == null)
        throw new ClassNotFoundException("No jar found with class named org.raspinloop.agent.PreMain");

    if (escaped)//from  www.ja v a2  s .  c o  m
        return toEscapedCliString(agentPath, jSonConfigName);
    else
        return toCliString(agentPath, jSonConfigName);
}

From source file:org.wisdom.template.thymeleaf.OgnlOpsByReflectionTest.java

@BeforeClass
public static void prepare() throws ClassNotFoundException {
    ClassLoader classLoader = new ClassLoader() {
        @Override/*from  w  w w. jav a2  s . c om*/
        public Class<?> loadClass(String name) throws ClassNotFoundException {
            if (name.equals(OgnlOps.class.getName())) {
                byte[] clazz;
                try {
                    clazz = FileUtils.readFileToByteArray(new File("target/classes/ognl/OgnlOps.class"));
                } catch (IOException e) {
                    throw new ClassNotFoundException("Cannot define the class");
                }
                return defineClass(OgnlOps.class.getName(), clazz, 0, clazz.length);
            } else {
                return OgnlOpsByReflectionTest.class.getClassLoader().loadClass(name);
            }
        }
    };
    clazz = classLoader.loadClass(OgnlOps.class.getName());
}

From source file:com.germinus.easyconf.ClasspathUtil.java

/**
 * Return the Class object of the specified class name by searching the
 * current classpath and the system classpath.
 *
 * @param name the name of the class/*from w w w. j a va2 s  . c  o  m*/
 *
 * @return the <code>Class</code> instance
 */
public static Class locateClass(String name) throws ClassNotFoundException {
    Class foundClass = null;
    if (foundClass == null) {
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        try {
            foundClass = loader.loadClass(name);
            log.debug("Class loaded from the context classpath (" + name + ")");
        } catch (ClassNotFoundException ignore) {
        }
    }

    if (foundClass == null) {
        try {
            foundClass = ClassLoader.getSystemClassLoader().loadClass(name);
            log.debug("Class loaded from the system classpath (" + name + ")");
        } catch (ClassNotFoundException ignore) {
        }
    }
    if (foundClass == null) {
        throw new ClassNotFoundException(
                "Class " + name + " was not found " + "in context classpath nor system classpath");
    }
    return foundClass;
}