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:com.bstek.dorado.util.clazz.ClassUtils.java
@SuppressWarnings("rawtypes") public static Class forName(String className) throws ClassNotFoundException { try {// w w w.j a v a 2 s . c o m return org.apache.commons.lang.ClassUtils.getClass(className); } catch (Error e) { throw new ClassNotFoundException(e.getMessage(), e); } }
From source file:Main.java
public static Class<?> findClass(String className) throws ClassNotFoundException { // [JACKSON-597]: support primitive types (and void) if (className.indexOf('.') < 0) { if ("int".equals(className)) return Integer.TYPE; if ("long".equals(className)) return Long.TYPE; if ("float".equals(className)) return Float.TYPE; if ("double".equals(className)) return Double.TYPE; if ("boolean".equals(className)) return Boolean.TYPE; if ("byte".equals(className)) return Byte.TYPE; if ("char".equals(className)) return Character.TYPE; if ("short".equals(className)) return Short.TYPE; if ("void".equals(className)) return Void.TYPE; }//from ww w. j ava 2 s. co m // Two-phase lookup: first using context ClassLoader; then default Throwable prob = null; ClassLoader loader = Thread.currentThread().getContextClassLoader(); if (loader != null) { try { return Class.forName(className, true, loader); } catch (Exception e) { prob = getRootCause(e); } } try { return Class.forName(className); } catch (Exception e) { if (prob == null) { prob = getRootCause(e); } } if (prob instanceof RuntimeException) { throw (RuntimeException) prob; } throw new ClassNotFoundException(prob.getMessage(), prob); }
From source file:edu.northwestern.bioinformatics.studycalendar.utility.osgimosis.FileClassLoader.java
@Override protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { log.trace("Looking for " + name); Class<?> found = findLoadedClass(name); if (found != null) { log.trace("Already loaded"); return found; }//from w w w .j a va 2 s . c o m File f = new File(root, name.replaceAll("\\.", "/") + ".class"); if (!f.exists()) { log.trace(f + " does not exist; going to system classloader"); return super.loadClass(name, resolve); } byte[] contents; try { contents = IOUtils.toByteArray(new FileInputStream(f)); } catch (IOException e) { throw new ClassNotFoundException("Could not read " + f, e); } log.trace("Defining from " + f); return defineClass(name, contents, 0, contents.length); }
From source file:com.l2jfree.gameserver.util.JarClassLoader.java
@Override public Class<?> findClass(String name) throws ClassNotFoundException { try {//from w ww . j a va 2 s . co m byte[] b = loadClassData(name); return defineClass(name, b, 0, b.length); } catch (Exception e) { throw new ClassNotFoundException(name, e); } }
From source file:fi.jumi.threadsafetyagent.util.TransformationTestClassLoader.java
@Override protected Class<?> findClass(String name) throws ClassNotFoundException { try {// w w w.ja v a 2 s . c o m byte[] b = transformer.transform(this, name, null, null, readClassBytes(name)); if (dirToWriteClasses != null) { try { FileUtils.writeByteArrayToFile(new File(dirToWriteClasses, name + ".class"), b); } catch (IOException e) { throw new RuntimeException(e); } } return defineClass(name, b, 0, b.length); } catch (IllegalClassFormatException e) { throw new ClassNotFoundException(name, e); } }
From source file:net.arnx.jsonic.web.extension.SpringContainer.java
@Override public Object getComponent(String className) throws Exception { Object component;/*from w w w . j av a 2 s. c om*/ try { component = appContext.getBean(className); } catch (Exception e) { throw new ClassNotFoundException("class not found: " + className, e); } if (component instanceof ApplicationContextAware) { ((ApplicationContextAware) component).setApplicationContext(appContext); } for (Method method : component.getClass().getMethods()) { Class<?>[] params = method.getParameterTypes(); if (void.class.equals(method.getReturnType()) && method.getName().startsWith("set") && params.length == 1) { Class<?> c = params[0]; if (HttpServletRequest.class.equals(c)) { method.invoke(component, ExternalContext.getRequest()); } else if (HttpServletResponse.class.equals(c)) { method.invoke(component, ExternalContext.getResponse()); } } } return component; }
From source file:nu.mine.kino.web.JSONICContainer.java
@Override public Object getComponent(String className) throws Exception { printheeader();//from w ww. ja v a 2s . com Object component; try { component = appContext.getBean(className); } catch (Exception e) { throw new ClassNotFoundException("class not found: " + className, e); } if (component instanceof ApplicationContextAware) { ((ApplicationContextAware) component).setApplicationContext(appContext); } for (Method method : component.getClass().getMethods()) { Class<?>[] params = method.getParameterTypes(); if (void.class.equals(method.getReturnType()) && method.getName().startsWith("set") && params.length == 1) { Class<?> c = params[0]; if (HttpServletRequest.class.equals(c)) { method.invoke(component, ExternalContext.getRequest()); } else if (HttpServletResponse.class.equals(c)) { method.invoke(component, ExternalContext.getResponse()); } } } return component; }
From source file:com.reactive.hzdfs.utils.EntityFinder.java
/** * //w w w. j a v a 2 s.c o m * @param provider * @param basePkg * @return * @throws ClassNotFoundException */ private static Set<Class<?>> findComponents(ClassPathScanningCandidateComponentProvider provider, String basePkg) throws ClassNotFoundException { Set<BeanDefinition> beans = null; String pkg = ""; try { pkg = StringUtils.hasText(basePkg) ? basePkg : EntityFinder.class.getPackage().getName(); beans = provider.findCandidateComponents(pkg); } catch (Exception e) { throw new ClassNotFoundException("Unable to scan for classes under given base package", new IllegalArgumentException("Package=> " + pkg, e)); } Set<Class<?>> classes = new HashSet<>(); if (beans != null && !beans.isEmpty()) { classes = new HashSet<>(beans.size()); for (BeanDefinition bd : beans) { classes.add(Class.forName(bd.getBeanClassName())); } } else { log.warn(">> Did not find any classes under the given base package [" + basePkg + "]"); } return classes; }
From source file:org.teavm.flavour.mp.impl.ProxyClassLoader.java
@Override protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { if (!isCompileTimeClass(name)) { return super.loadClass(name, resolve); } else {/*from ww w. ja v a2s . c o m*/ try (InputStream input = getResourceAsStream(name.replace('.', '/') + ".class")) { byte[] array = instrumentation.instrument(IOUtils.toByteArray(input)); return defineClass(name, array, 0, array.length); } catch (IOException e) { throw new ClassNotFoundException("Error reading bytecode of class " + name, e); } } }
From source file:com.google.code.ddom.commons.cl.ClassRef.java
/** * Load the definition of the class identified by this object. * /*from w ww . j a va 2 s.c o m*/ * @return the class definition, i.e. the content of the corresponding class file * @throws ClassNotFoundException * if the class was not found or an error occurred when loading the class definition */ public byte[] getClassDefinition() throws ClassNotFoundException { InputStream in = getClassDefinitionAsStream(); try { try { return IOUtils.toByteArray(in); } finally { in.close(); } } catch (IOException ex) { throw new ClassNotFoundException(className, ex); } }