List of usage examples for java.lang ClassNotFoundException ClassNotFoundException
public ClassNotFoundException(String s)
ClassNotFoundException
with the specified detail message. From source file:org.echocat.nodoodle.classloading.FileClassLoader.java
@Override protected synchronized Class<?> findClass(final String name) throws ClassNotFoundException { ensureNotClosed();/*from w w w . jav a2 s . c om*/ try { return doPrivileged(new PrivilegedExceptionAction<Class<?>>() { @Override public Class<?> run() throws Exception { Class<?> result; result = null; final String path = name.replace('.', '/').concat(".class"); final Iterator<File> i = _directories.iterator(); while (result == null && i.hasNext()) { final File directory = i.next(); final File file = new File(directory, path); if (file.isFile()) { result = defineClass(name, new DirectoryResource(directory, file)); } } if (result == null) { final Iterator<JarFile> j = _jarFiles.iterator(); while (result == null && j.hasNext()) { final JarFile jarFile = j.next(); final JarEntry jarEntry = jarFile.getJarEntry(path); if (jarEntry != null) { result = defineClass(name, new JarResource(jarFile, jarEntry)); } } } if (result == null) { throw new ClassNotFoundException(name); } return result; } }, _acc); } catch (PrivilegedActionException e) { final Exception exception = e.getException(); if (exception instanceof ClassNotFoundException) { throw (ClassNotFoundException) exception; } else { throw new RuntimeException(e); } } }
From source file:org.apache.openaz.xacml.util.FactoryFinder.java
public static <T> T newInstance(String className, Class<T> classExtends, ClassLoader cl, boolean doFallback, Properties xacmlProperties) throws FactoryException { try {/*from w w w . j a v a 2 s . c o m*/ Class<?> providerClass = getProviderClass(className, cl, doFallback); if (classExtends.isAssignableFrom(providerClass)) { Object instance = null; if (xacmlProperties == null) { instance = providerClass.newInstance(); } else { // // Search for a constructor that takes Properties // for (Constructor<?> constructor : providerClass.getDeclaredConstructors()) { Class<?>[] params = constructor.getParameterTypes(); if (params.length == 1 && params[0].isAssignableFrom(Properties.class)) { instance = constructor.newInstance(xacmlProperties); } } if (instance == null) { logger.warn("No constructor that takes a Properties object."); instance = providerClass.newInstance(); } } if (logger.isTraceEnabled()) { logger.trace("Created new instance of " + providerClass + " using ClassLoader: " + cl); } return classExtends.cast(instance); } else { throw new ClassNotFoundException( "Provider " + className + " does not extend " + classExtends.getCanonicalName()); } } catch (ClassNotFoundException ex) { throw new FactoryException("Provider " + className + " not found", ex); } catch (Exception ex) { throw new FactoryException("Provider " + className + " could not be instantiated: " + ex.getMessage(), ex); } }
From source file:org.bimserver.plugins.classloaders.JarClassLoader.java
@Override protected Class<?> findClass(String name) throws ClassNotFoundException { String fileName = name.replace(".", "/") + ".class"; if (loadedClasses.containsKey(fileName)) { return loadedClasses.get(fileName); }/*from w ww . j ava2 s .c om*/ if (map.containsKey(fileName)) { byte[] bs = map.get(fileName); InflaterInputStream inflaterInputStream = new InflaterInputStream(new ByteArrayInputStream(bs)); ByteArrayOutputStream uncompressed = new ByteArrayOutputStream(); try { IOUtils.copy(inflaterInputStream, uncompressed); } catch (IOException e) { e.printStackTrace(); } byte[] byteArray = uncompressed.toByteArray(); Class<?> defineClass = defineClass(name, byteArray, 0, byteArray.length); loadedClasses.put(fileName, defineClass); /* * 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 (defineClass != 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); } } } // The original class file cannot be loaded for other purposes after this (would be strange), this saves memory map.remove(fileName); return defineClass; } throw new ClassNotFoundException(name); }
From source file:org.bimserver.plugins.classloaders.MemoryJarClassLoader.java
@Override public Class<?> findClass(String name) throws ClassNotFoundException { String fileName = name.replace(".", "/") + ".class"; if (loadedClasses.containsKey(fileName)) { return loadedClasses.get(fileName); }//from ww w .jav a 2 s . com if (map.containsKey(fileName)) { byte[] bs = map.get(fileName); InflaterInputStream inflaterInputStream = new InflaterInputStream(new ByteArrayInputStream(bs)); ByteArrayOutputStream uncompressed = new ByteArrayOutputStream(); try { IOUtils.copy(inflaterInputStream, uncompressed); } catch (IOException e) { LOGGER.error("", e); } byte[] byteArray = uncompressed.toByteArray(); Class<?> defineClass = defineClass(name, byteArray, 0, byteArray.length); loadedClasses.put(fileName, defineClass); /* * 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 (defineClass != 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); } } } // The original class file cannot be loaded for other purposes after this (would be strange), this saves memory map.remove(fileName); return defineClass; } throw new ClassNotFoundException(name); }
From source file:io.promagent.internal.HookMetadataParser.java
private byte[] readBinaryRepresentation(String className) throws ClassNotFoundException { String classFileName = "/" + className.replace(".", "/") + ".class"; try (InputStream stream = getResourceAsStream(classFileName)) { if (stream == null) { throw new ClassNotFoundException(className); }/*from w w w .java 2s. c o m*/ return IOUtils.toByteArray(stream); } catch (IOException e) { throw new ClassNotFoundException(className, e); } }
From source file:org.apache.hadoop.util.ApplicationClassLoader.java
@Override protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { if (LOG.isDebugEnabled()) { LOG.debug("Loading class: " + name); }//from ww w . j av a2s . c o m Class<?> c = findLoadedClass(name); ClassNotFoundException ex = null; if (c == null && !isSystemClass(name, systemClasses)) { // Try to load class from this classloader's URLs. Note that this is like // the servlet spec, not the usual Java 2 behaviour where we ask the // parent to attempt to load first. try { c = findClass(name); if (LOG.isDebugEnabled() && c != null) { LOG.debug("Loaded class: " + name + " "); } } catch (ClassNotFoundException e) { if (LOG.isDebugEnabled()) { LOG.debug(e); } ex = e; } } if (c == null) { // try parent c = parent.loadClass(name); if (LOG.isDebugEnabled() && c != null) { LOG.debug("Loaded class from parent: " + name + " "); } } if (c == null) { throw ex != null ? ex : new ClassNotFoundException(name); } if (resolve) { resolveClass(c); } return c; }
From source file:org.apache.axis2.addressing.RelatesTo.java
/** * Restore the contents of the object that was * previously saved.//from w w w . j a v a 2 s .c o m * <p/> * NOTE: The field data must read back in the same order and type * as it was written. Some data will need to be validated when * resurrected. * * @param in The stream to read the object contents from * @throws IOException * @throws ClassNotFoundException */ public void readExternal(ObjectInput inObject) throws IOException, ClassNotFoundException { SafeObjectInputStream in = SafeObjectInputStream.install(inObject); // serialization version ID long suid = in.readLong(); // revision ID int revID = in.readInt(); // make sure the object data is in a version we can handle if (suid != serialVersionUID) { throw new ClassNotFoundException(ExternalizeConstants.UNSUPPORTED_SUID); } // make sure the object data is in a revision level we can handle if (revID != REVISION_2) { throw new ClassNotFoundException(ExternalizeConstants.UNSUPPORTED_REVID); } //--------------------------------------------------------- // various strings //--------------------------------------------------------- // String relationshipType relationshipType = (String) in.readObject(); // String value value = (String) in.readObject(); //--------------------------------------------------------- // collections and lists //--------------------------------------------------------- // ArrayList extensibilityAttributes extensibilityAttributes = in.readArrayList(); }
From source file:org.bimserver.plugins.classloaders.FileJarClassLoader.java
@Override public Class<?> findClass(String name) throws ClassNotFoundException { String fileName = name.replace(".", "/") + ".class"; if (loadedClasses.containsKey(fileName)) { return loadedClasses.get(fileName); }/*from www . ja v a2 s . c o m*/ try { Lazy<InputStream> lazyInputStream = findPath(fileName); if (lazyInputStream == null) { throw new ClassNotFoundException(name); } InputStream inputStream = lazyInputStream.get(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); try { IOUtils.copy(inputStream, byteArrayOutputStream); } finally { inputStream.close(); } Class<?> defineClass = defineClass(name, byteArrayOutputStream.toByteArray(), 0, byteArrayOutputStream.toByteArray().length); loadedClasses.put(fileName, defineClass); /* * 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 (defineClass != 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 defineClass; } catch (FileNotFoundException e) { throw new ClassNotFoundException(name); } catch (IOException e) { throw new ClassNotFoundException(name); } }
From source file:hu.ppke.itk.nlpg.purepos.cli.PurePos.java
/** * Loads the latest Humor jar file and create an analyzer instance * // w w w .j a v a 2s .co m * @return analyzer instance */ protected static IMorphologicalAnalyzer loadHumor() throws InstantiationException, IllegalAccessException, ClassNotFoundException, MalformedURLException { String humorPath = System.getProperty("humor.path"); if (humorPath == null) throw new ClassNotFoundException("Humor jar file is not present"); File dir = new File(humorPath); File[] candidates = dir.listFiles(new FilenameFilter() { public boolean accept(File dir, String filename) { return filename.endsWith(".jar") && filename.startsWith("humor-"); } }); Arrays.sort(candidates); @SuppressWarnings("deprecation") URL humorURL = candidates[candidates.length - 1].toURL(); URLClassLoader myLoader = new URLClassLoader(new URL[] { humorURL }, PurePos.class.getClassLoader()); Class<?> humorClass = Class.forName("hu.ppke.itk.nlpg.purepos.morphology.HumorAnalyzer", true, myLoader); return (IMorphologicalAnalyzer) humorClass.newInstance(); }
From source file:org.atricore.idbus.kernel.planning.jbpm.ProcessRegistryImpl.java
public Class findProcessActionClass(String qualifiedActionName) throws ClassNotFoundException { Class foundClass = null;//from www . ja va2 s . co m Set<Bundle> bundleActionKeys = bundleActions.keySet(); if (logger.isDebugEnabled()) logger.debug("Looking in " + bundleActions.size() + " bundles for process action class " + qualifiedActionName); for (Bundle bundle : bundleActionKeys) { Set<ProcessAction> processActions = bundleActions.get(bundle); if (logger.isTraceEnabled()) logger.trace("Bundle (" + bundle.getBundleId() + ") has " + processActions.size() + " actions"); for (ProcessAction processAction : processActions) { if (logger.isTraceEnabled()) logger.trace("Bundle (" + bundle.getBundleId() + ") has " + processAction.getClass().getName() + " action"); if (processAction.getQualifiedClassName().equals(qualifiedActionName)) { foundClass = bundle.loadClass(qualifiedActionName); } } } if (foundClass == null) { logger.debug("Class : " + qualifiedActionName + " not found, is this a process action class?"); throw new ClassNotFoundException(qualifiedActionName); } return foundClass; }