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:org.eclectic.idc.jvm.runtime.IdcClassLoader.java
public Class<?> loadClass(final String name) throws ClassNotFoundException { if (byteCodeClasses.containsKey(name)) { try {/*from ww w. j a v a 2s. c o m*/ byte[] bytecode = transform(name, new ByteArrayInputStream(byteCodeClasses.get(name).bytes)); return super.defineClass(name, bytecode, 0, bytecode.length); } catch (IOException ex) { ex.printStackTrace(); throw new ClassNotFoundException(name + " " + ex.getMessage(), ex); } } final int i = name.indexOf('$'); final String key; if (i == -1) { key = name; } else { key = name.substring(0, i); } if (instrument.contains(key) || load.contains(key)) { try { final InputStream is = getClass().getResourceAsStream("/" + name.replace('.', '/') + ".class"); final byte[] bytecode; if (instrument.contains(key)) { System.err.println("Instrumenting: " + name); bytecode = transform(name, is); } else { System.err.println("Loading: " + name); bytecode = new ClassReader(is).b; } return super.defineClass(name, bytecode, 0, bytecode.length); } catch (Throwable ex) { // System.err.println("Load error: " + ex.toString()); ex.printStackTrace(); throw new ClassNotFoundException(name + " " + ex.getMessage(), ex); } } // System.err.println("Delegating: " + name); return super.loadClass(name); }
From source file:org.wso2.appserver.integration.common.utils.SqlDataSourceUtil.java
private void createDataBase(String driver, String jdbc, String user, String password) throws ClassNotFoundException, SQLException, XPathExpressionException { if (automationContext == null) { init();//from www. j av a2 s . c o m } try { DatabaseManager dbm = DatabaseFactory.getDatabaseConnector(driver, jdbc, user, password); dbm.executeUpdate("DROP DATABASE IF EXISTS " + databaseName); dbm.executeUpdate("CREATE DATABASE " + databaseName); jdbcUrl = jdbc + "/" + databaseName; dbm.disconnect(); } catch (ClassNotFoundException e) { log.error("Class Not Found. Check MySql-jdbc Driver in classpath: ", e); throw new ClassNotFoundException("Class Not Found. Check MySql-jdbc Driver in classpath: ", e); } catch (SQLException e) { log.error("SQLException When executing SQL: ", e); throw new SQLException("SQLException When executing SQL: ", e); } }
From source file:com.pentaho.big.data.bundles.impl.shim.common.ShimBridgingClassloader.java
@Override protected Class<?> findClass(String name) throws ClassNotFoundException { int lastIndexOfDot = name.lastIndexOf('.'); final String packageName; final String translatedPath; final String translatedName; if (lastIndexOfDot >= 0) { packageName = name.substring(0, lastIndexOfDot); if (getPackage(packageName) == null) { definePackage(packageName, null, null, null, null, null, null, null); }//from ww w .jav a 2 s .c o m translatedPath = "/" + packageName.replace('.', '/'); translatedName = name.substring(lastIndexOfDot + 1) + ".class"; } else { packageName = ""; translatedPath = "/"; translatedName = name; } if (getPackage(packageName) == null) { definePackage(packageName, null, null, null, null, null, null, null); } List<URL> entries = bundleWiring.findEntries(translatedPath, translatedName, 0); if (entries.size() == 1) { byte[] bytes; try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) { IOUtils.copy(entries.get(0).openStream(), byteArrayOutputStream); bytes = byteArrayOutputStream.toByteArray(); } catch (IOException e) { throw new ClassNotFoundException("Unable to define class", e); } return defineClass(name, bytes, 0, bytes.length); } throw new ClassNotFoundException(); }
From source file:de.smartics.maven.plugin.jboss.modules.util.classpath.AbstractProjectClassLoader.java
/** * Opens a reader to the class file within the archive. * * @param className the name of the class to load. * @param fileName the name of the class file to load. * @param dirName the name of the directory the archive file is located. * @return the reader to the source file for the given class in the archive. * @throws ClassNotFoundException if the class cannot be found. *//* w w w.ja v a2 s . c o m*/ protected Class<?> loadClassFromLibrary(final String className, final String fileName, final File dirName) throws ClassNotFoundException { ensurePackageProvided(className); try { final JarFile jarFile = new JarFile(dirName); // NOPMD final JarEntry entry = jarFile.getJarEntry(fileName); if (entry != null) { InputStream in = null; try { in = new BufferedInputStream(jarFile.getInputStream(entry)); final byte[] data = IOUtils.toByteArray(in); final Class<?> clazz = defineClass(className, data, 0, data.length); return clazz; } finally { IOUtils.closeQuietly(in); } } } catch (final IOException e) { final String message = "Cannot load class '" + className + "' from file '" + dirName + "'."; LOG.fine(message); throw new ClassNotFoundException(message, e); } final String message = "Cannot load class '" + className + "' from file '" + dirName + "'."; LOG.fine(message); throw new ClassNotFoundException(message); }
From source file:org.apache.accumulo.start.classloader.vfs.ContextManager.java
public <U> Class<? extends U> loadClass(String context, String classname, Class<U> extension) throws ClassNotFoundException { try {//from w w w .java2s. co m return getClassLoader(context).loadClass(classname).asSubclass(extension); } catch (IOException e) { throw new ClassNotFoundException("IO Error loading class " + classname, e); } }
From source file:io.apiman.common.plugin.PluginClassLoader.java
/** * @see java.lang.ClassLoader#findClass(java.lang.String) *///from w ww . j a v a 2s . c o m @Override protected Class<?> findClass(String name) throws ClassNotFoundException { InputStream inputStream = null; try { inputStream = findClassContent(name); if (inputStream == null) { return super.findClass(name); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(inputStream, baos); byte[] bytes = baos.toByteArray(); return defineClass(name, bytes, 0, bytes.length); } catch (IOException e) { throw new ClassNotFoundException(name, e); } finally { IOUtils.closeQuietly(inputStream); } }
From source file:org.nebulaframework.deployment.classloading.GridNodeClassLoader.java
/** * Attempts to find the class definition for the given class name, by first * searching the local cache, and then through the remote * {@link ClassLoadingService}.// w ww . ja v a 2s.c om * * @param name * binary name of the class * * @return The {@code Class<?>} object for requested class, if found * * @throws ClassNotFoundException * if unable to find the class */ @Override protected Class<?> findClass(final String name) throws ClassNotFoundException { log.debug("[GridNodeClassLoader] Finding Class : " + name); Class<?> cls = null; // Attempt remote load try { log.debug("[GridNodeClassLoader] Attempt Remote Loading : " + name); // Get bytes for class from remote service byte[] bytes = AccessController.doPrivileged(new PrivilegedExceptionAction<byte[]>() { @Override public byte[] run() throws ClassNotFoundException { // If we don't know owner if (ownerId == null) { return classLoadingService.findClass(jobId, name); } else { // If we know owner return classLoadingService.findClass(ownerId, name); } } }); cls = defineClass(name, bytes, 0, bytes.length, REMOTE_CODESOURCE); log.debug("[GridNodeClassLoader] Remote Loaded : " + name); return cls; } catch (Exception ex) { log.warn("[GridNodeClassLoader] Exception while Remote Loading ", ex); throw new ClassNotFoundException("Class not found due to Exception", ex); } }
From source file:io.squark.nestedjarclassloader.Module.java
private Class<?> getLoadedClass(String className, boolean resolve) throws ClassNotFoundException { synchronized (getClassLoadingLock(className)) { Class<?> loadedClass = findLoadedClass(className); if (classes.containsKey(className)) { return classes.get(className); }//from w ww . ja v a 2 s .c o m if (byteCache.containsKey(className)) { definePackageForClass(className); byte[] classBytes = byteCache.get(className); if (loadedClass == null) { //We got here without Exception, meaning class was filtered from proxying. Load normally: try { loadedClass = defineClass(className, classBytes, 0, classBytes.length, this.getClass().getProtectionDomain()); } catch (NoClassDefFoundError | IncompatibleClassChangeError e) { throw new ClassNotFoundException(className, e); } } classes.put(className, loadedClass); if (resolve) { resolveClass(loadedClass); } return loadedClass; } else { return null; } } }
From source file:org.wso2.appserver.integration.common.utils.SqlDataSourceUtil.java
private void executeUpdate(List<File> sqlFileList) throws IOException, ClassNotFoundException, SQLException, XPathExpressionException { DatabaseManager dbm = null;//from w w w . j a va2s . c o m try { dbm = DatabaseFactory.getDatabaseConnector(jdbcDriver, jdbcUrl, databaseUser, databasePassword); for (File sql : sqlFileList) { dbm.executeUpdate(sql); } } catch (IOException e) { log.error("IOException When reading SQL files: ", e); throw new IOException("IOException When reading SQL files: ", e); } catch (ClassNotFoundException e) { log.error("Class Not Found. Check MySql-jdbc Driver in classpath: " + e); throw new ClassNotFoundException("Class Not Found. Check MySql-jdbc Driver in classpath: ", e); } catch (SQLException e) { log.error("SQLException When executing SQL: " + e); throw new SQLException("SQLException When executing SQL: ", e); } finally { if (dbm != null) { dbm.disconnect(); } } }
From source file:org.nebulaframework.deployment.classloading.GridArchiveClassLoader.java
/** * Attempts to find the given Class with in the {@code GridArchive}. If * found (either as direct class file or with in a {@code .jar} library * inside {@code .nar} file), returns the Class instance for it. * /*ww w . j av a2 s .c o m*/ * @return the {@code Class<?>} instance for the class to be loaded * * @throws ClassNotFoundException if unable to find the class */ @Override public Class<?> findClass(String name) throws ClassNotFoundException { try { // Convert class name to file name final String fileName = name.replaceAll("\\.", "/") + ".class"; // Search in Archive | Exception if failed byte[] bytes = AccessController.doPrivileged(new PrivilegedExceptionAction<byte[]>() { @Override public byte[] run() throws IOException, ClassNotFoundException { return findInArchive(fileName); } }); // If found, define class and return return defineClass(name, bytes, 0, bytes.length, REMOTE_CODESOURCE); } catch (Exception e) { throw new ClassNotFoundException("Unable to locate class", e); } }