List of usage examples for java.lang ClassNotFoundException ClassNotFoundException
public ClassNotFoundException(String s)
ClassNotFoundException
with the specified detail message. From source file:com.wavemaker.common.util.ThrowawayFileClassLoader.java
@Override protected Class<?> findClass(String name) throws ClassNotFoundException { if (this.classPath == null) { throw new ClassNotFoundException("invalid search root: " + this.classPath); } else if (name == null) { throw new ClassNotFoundException(MessageResource.NULL_CLASS.getMessage()); }// w ww . j av a2 s . c o m String classNamePath = name.replace('.', '/') + ".class"; byte[] fileBytes = null; try { InputStream is = null; JarFile jarFile = null; for (Resource entry : this.classPath) { if (entry.getFilename().toLowerCase().endsWith(".jar")) { jarFile = new JarFile(entry.getFile()); ZipEntry ze = jarFile.getEntry(classNamePath); if (ze != null) { is = jarFile.getInputStream(ze); break; } else { jarFile.close(); } } else { Resource classFile = entry.createRelative(classNamePath); if (classFile.exists()) { is = classFile.getInputStream(); break; } } } if (is != null) { try { fileBytes = IOUtils.toByteArray(is); is.close(); } finally { if (jarFile != null) { jarFile.close(); } } } } catch (IOException e) { throw new ClassNotFoundException(e.getMessage(), e); } if (name.contains(".")) { String packageName = name.substring(0, name.lastIndexOf('.')); if (getPackage(packageName) == null) { definePackage(packageName, "", "", "", "", "", "", null); } } Class<?> ret; if (fileBytes == null) { ret = ClassLoaderUtils.loadClass(name, this.parentClassLoader); } else { ret = defineClass(name, fileBytes, 0, fileBytes.length); } if (ret == null) { throw new ClassNotFoundException( "Couldn't find class " + name + " in expected classpath: " + this.classPath); } return ret; }
From source file:fi.jumi.threadsafetyagent.util.TransformationTestClassLoader.java
private byte[] readClassBytes(String name) throws ClassNotFoundException { InputStream in = getResourceAsStream(name.replaceAll("\\.", "/") + ".class"); if (in == null) { throw new ClassNotFoundException(name); }//from w w w .jav a2s . co m try { return IOUtils.toByteArray(in); } catch (IOException e) { throw new ClassNotFoundException(name, e); } }
From source file:com.haulmont.cuba.core.sys.javacl.CompilationScope.java
private void collectInformation(String rootClassName) throws ClassNotFoundException { if (processed.contains(rootClassName)) { return;/*from w w w .j a va 2 s .c om*/ } File srcFile = sourceProvider.getSourceFile(rootClassName); processed.add(rootClassName); TimestampClass timeStampClazz = javaClassLoader.getTimestampClass(rootClassName); if (timeStampClazz != null) { if (FileUtils.isFileNewer(srcFile, timeStampClazz.timestamp)) { compilationNeeded.add(rootClassName); } else if (!srcFile.exists()) { throw new ClassNotFoundException( String.format("Class %s not found. No sources found in file system.", rootClassName)); } for (String dependencyName : timeStampClazz.dependencies) { collectInformation(dependencyName); } } else { compilationNeeded.add(rootClassName); } }
From source file:m3.classe.M3ClassLoader.java
public final Class findClass(String name) throws ClassNotFoundException { byte[] b = loadClassData(name); if (b == null) { throw new ClassNotFoundException(name); }/* ww w .j a v a2 s . co m*/ return defineClass(name, b, 0, b.length); }
From source file:org.raspinloop.fmi.VMRunnerUtils.java
public static String getRunnerAgentArgument(Collection<File> jars, String jSonConfigName, boolean escaped) throws URISyntaxException, ClassNotFoundException, IOException { Path agentPath = filterJarContainingClass(jars, "org.raspinloop.agent.PreMain"); if (agentPath == null) throw new ClassNotFoundException("No jar found with class named org.raspinloop.agent.PreMain"); if (escaped)/* ww w.j a va 2 s.c o m*/ return toEscapedCliString(agentPath, jSonConfigName); else return toCliString(agentPath, jSonConfigName); }
From source file:net.mindengine.blogix.utils.BlogixUtils.java
private static Class<?> findClassInClassLoaders(ClassLoader[] classLoaders, String classPath) throws ClassNotFoundException { for (ClassLoader classLoader : classLoaders) { try {// ww w.j a v a 2 s .c om return classLoader.loadClass(classPath); } catch (ClassNotFoundException e) { } } throw new ClassNotFoundException(classPath); }
From source file:org.mule.module.launcher.application.CompositeApplicationClassLoader.java
@Override public Class<?> loadClass(String s) throws ClassNotFoundException { for (ClassLoader classLoader : classLoaders) { try {/*from w w w.j av a2 s. co m*/ Class<?> aClass = classLoader.loadClass(s); if (logger.isDebugEnabled()) { logger.debug(String.format("Class '%s' loaded from classLoader '%s", s, classLoader)); } return aClass; } catch (ClassNotFoundException e) { // Ignoring } } throw new ClassNotFoundException(String.format("Cannot load class '%s'", s)); }
From source file:com.compomics.pride_asa_pipeline.core.logic.spectrum.SpectrumParserFactory.java
public static JMzReader getJMzReader(File inputFile) throws ClassNotFoundException, MzXMLParsingException, JMzReaderException { currentInputFile = inputFile;/*from w w w. j a v a 2 s . c o m*/ JMzReader parser = null; String extension = FilenameUtils.getExtension(inputFile.getAbsolutePath()); switch (extension.toLowerCase()) { case "mzxml": LOGGER.info("Detected mzXml file extension."); currentType = FileParserType.MZXML; parser = new MzXMLFile(inputFile); break; case "mzml": LOGGER.info("Detected mzml file extension."); currentType = FileParserType.MZML; parser = new MzMlWrapper(inputFile); break; case "dta": LOGGER.info("Detected dta file extension."); currentType = FileParserType.DTA; parser = new DtaFile(inputFile); break; case "mgf": LOGGER.info("Detected mgf file extension."); currentType = FileParserType.MGF; parser = new MgfFile(inputFile); break; case "ms2": LOGGER.info("Detected ms2 file extension."); currentType = FileParserType.MS2; parser = new Ms2File(inputFile); break; case "mzData": LOGGER.info("Detected mzData file extension."); currentType = FileParserType.MZDATA; parser = new MzDataFile(inputFile); break; case "xml": LOGGER.info("Detected xml file extension."); currentType = FileParserType.PRIDEXML; parser = new PRIDEXmlWrapper(inputFile); break; case "pkl": LOGGER.info("Detected pkl file extension."); currentType = FileParserType.PKL; parser = new PklFile(inputFile); break; default: throw new ClassNotFoundException("No suitable parser was found for the inputfile."); } return parser; }
From source file:org.springframework.boot.web.embedded.tomcat.TomcatEmbeddedWebappClassLoader.java
@Override public Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { synchronized (getClassLoadingLock(name)) { Class<?> result = findExistingLoadedClass(name); result = (result != null) ? result : doLoadClass(name); if (result == null) { throw new ClassNotFoundException(name); }//from www . j a v a2 s .c o m return resolveIfNecessary(result, resolve); } }
From source file:org.apache.openaz.xacml.std.pip.finders.ConfigurableEngineFinder.java
/** * Creates an instance of the given <code>String</code> className for an object implementing the * <code>ConfigurableEngine</code> interface. * * @param className the <code>String</code> class name of the engine * @return an instance of the given class name * @throws org.apache.openaz.xacml.api.pip.PIPException *//*from ww w.j a va2 s. co m*/ protected ConfigurableEngine newEngine(String className) throws PIPException { Class<?> classForEngine = null; try { classForEngine = Class.forName(className); if (!ConfigurableEngine.class.isAssignableFrom(classForEngine)) { throw new ClassNotFoundException( "Engine class \"" + className + "\" does not implement ConfigurableEngine"); } return ConfigurableEngine.class.cast(classForEngine.newInstance()); } catch (Exception ex) { throw new PIPException("Exception getting Class for \"" + className + "\"" + ex.getLocalizedMessage()); } }