List of usage examples for java.lang ClassNotFoundException getCause
public synchronized Throwable getCause()
From source file:org.hyperic.hq.product.jmx.MxUtil.java
static String getUrlFromPid(String ptql) throws IOException { Sigar sigar = new Sigar(); String address;/*from w w w . ja v a2s . com*/ long pid; try { pid = new ProcessFinder(sigar).findSingleProcess(ptql); Class caddrLinkClass = Class.forName("sun.management.ConnectorAddressLink"); Method importFrom = caddrLinkClass.getMethod("importFrom", new Class[] { Integer.TYPE }); address = (String) importFrom.invoke(caddrLinkClass, new Object[] { new Integer((int) pid) }); } catch (ClassNotFoundException e) { String jvm = System.getProperty("java.vm.name") + " " + System.getProperty("java.vm.version"); throw new IOException(ptql + " " + e.getMessage() + " not supported by " + jvm); } catch (InvocationTargetException e) { throw new IOException(ptql + " " + e.getCause()); } catch (Exception e) { throw new IOException(ptql + " " + e); } finally { sigar.close(); } if (address == null) { throw new IOException("Unable to determine " + PROP_JMX_URL + " using vmid=" + pid + ". Server must be started with: " + "-Dcom.sun.management.jmxremote"); } log.debug(PTQL_PREFIX + ptql + " resolved to vmid=" + pid + ", " + PROP_JMX_URL + "=" + address); return address; }
From source file:com.baidu.terminator.register.scanner.AnnotationScanner.java
@SuppressWarnings("unchecked") public List<Class<? extends T>> scanAnnotatedClass() { List<Class<? extends T>> classList = new ArrayList<Class<? extends T>>(); ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider( false);/*from ww w. j a v a 2 s .co m*/ scanner.addIncludeFilter(new AnnotationTypeFilter(annotationType)); Set<BeanDefinition> components = scanner.findCandidateComponents(scannerPackage); for (BeanDefinition bd : components) { String className = bd.getBeanClassName(); try { Class<? extends T> clazz = (Class<? extends T>) Class.forName(className); classList.add(clazz); } catch (ClassNotFoundException e) { LOGGER.warn("can not find class" + className, e.getCause()); } } return classList; }
From source file:org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil.java
/** * Invoke 'getJar' on a JarFinder implementation. Useful for some job * configuration contexts (HBASE-8140) and also for testing on MRv2. First * check if we have HADOOP-9426. Lacking that, fall back to the backport. * @param my_class the class to find./* w ww . j a v a 2s . c o m*/ * @return a jar file that contains the class, or null. */ private static String getJar(Class<?> my_class) { String ret = null; String hadoopJarFinder = "org.apache.hadoop.util.JarFinder"; Class<?> jarFinder = null; try { LOG.debug("Looking for " + hadoopJarFinder + "."); jarFinder = Class.forName(hadoopJarFinder); LOG.debug(hadoopJarFinder + " found."); Method getJar = jarFinder.getMethod("getJar", Class.class); ret = (String) getJar.invoke(null, my_class); } catch (ClassNotFoundException e) { LOG.debug("Using backported JarFinder."); ret = JarFinder.getJar(my_class); } catch (InvocationTargetException e) { // function was properly called, but threw it's own exception. Unwrap it // and pass it on. throw new RuntimeException(e.getCause()); } catch (Exception e) { // toss all other exceptions, related to reflection failure throw new RuntimeException("getJar invocation failed.", e); } return ret; }
From source file:jenkins.model.RunIdMigrator.java
/** * Tries to move/rename a file from one path to another. * Uses {@link java.nio.file.Files#move} when available. * Does not use {@link java.nio.file.StandardCopyOption#REPLACE_EXISTING} or any other options. * TODO candidate for moving to {@link Util} *//*from ww w .j a v a2s. c om*/ static void move(File src, File dest) throws IOException { Class<?> pathC; try { pathC = Class.forName("java.nio.file.Path"); } catch (ClassNotFoundException x) { // Java 6, do our best if (dest.exists()) { throw new IOException(dest + " already exists"); } if (src.renameTo(dest)) { return; } throw new IOException("could not move " + src + " to " + dest); } try { Method toPath = File.class.getMethod("toPath"); Class<?> copyOptionAC = Class.forName("[Ljava.nio.file.CopyOption;"); Class.forName("java.nio.file.Files").getMethod("move", pathC, pathC, copyOptionAC).invoke(null, toPath.invoke(src), toPath.invoke(dest), Array.newInstance(copyOptionAC.getComponentType(), 0)); } catch (InvocationTargetException x) { Throwable cause = x.getCause(); if (cause instanceof IOException) { throw (IOException) cause; } else { throw new IOException(cause); } } catch (Exception x) { throw new IOException(x); } }
From source file:org.cloudgraph.hbase.mapreduce.GraphMapReduceSetup.java
/** * Invoke 'getJar' on a JarFinder implementation. Useful for some job * configuration contexts (HBASE-8140) and also for testing on MRv2. First * check if we have HADOOP-9426. Lacking that, fall back to the backport. * /*from w w w.ja v a 2s . co m*/ * @param my_class * the class to find. * @return a jar file that contains the class, or null. */ private static String getJar(Class<?> my_class) { String ret = null; String hadoopJarFinder = "org.apache.hadoop.util.JarFinder"; Class<?> jarFinder = null; try { LOG.debug("Looking for " + hadoopJarFinder + "."); jarFinder = Class.forName(hadoopJarFinder); LOG.debug(hadoopJarFinder + " found."); Method getJar = jarFinder.getMethod("getJar", Class.class); ret = (String) getJar.invoke(null, my_class); } catch (ClassNotFoundException e) { LOG.debug("Using backported JarFinder."); ret = JarFinder.getJar(my_class); } catch (InvocationTargetException e) { // function was properly called, but threw it's own exception. // Unwrap it // and pass it on. throw new RuntimeException(e.getCause()); } catch (Exception e) { // toss all other exceptions, related to reflection failure throw new RuntimeException("getJar invocation failed.", e); } return ret; }
From source file:org.mule.module.apikit.validation.io.JsonSchemaResource.java
@Override public InputStream getInputStream() throws IOException { try {//w w w . ja v a 2 s . c o m Class<?> clazz = this.classLoader.loadClass(className); return new ByteArrayInputStream(schemaCache.get(clazz)); } catch (ClassNotFoundException e) { throw new IOException(getDescription() + " cannot be found", e); } catch (ExecutionException e) { throw new IOException(getDescription() + " cannot be found", e.getCause()); } }
From source file:org.mule.module.apikit.validation.io.XmlSchemaResource.java
@Override public InputStream getInputStream() throws IOException { try {//www . java 2 s .c om Class<?> clazz = this.classLoader.loadClass(className); return new ByteArrayInputStream(schemaCache.get(clazz)); } catch (ClassNotFoundException e) { throw new IOException(getDescription() + " cannot be found", e); } catch (ExecutionException e) { throw new IOException(getDescription() + " execution exception", e.getCause()); } }
From source file:com.baidu.terminator.manager.service.LinkControlServiceImpl.java
@Override public Class<?> getPluginClass(Link link, WorkMode mode) { Class<?> clazz = null;//from www . j a v a 2 s .c o m String className = null; if (WorkMode.RECORD.equals(mode) || WorkMode.REPLAY.equals(mode)) { className = link.getSignClass(); } else if (WorkMode.STUB.equals(mode)) { className = link.getExtractClass(); } if (StringUtils.isBlank(className)) { if (WorkMode.RECORD.equals(mode) || WorkMode.REPLAY.equals(mode)) { clazz = protocolRegister.getDefaultSignerMap(link.getProtocolType()); } else if (WorkMode.STUB.equals(mode)) { clazz = protocolRegister.getDefaultExtractorMap(link.getProtocolType()); } } else { try { clazz = Class.forName(className); } catch (ClassNotFoundException e) { if (WorkMode.RECORD.equals(mode) || WorkMode.REPLAY.equals(mode)) { throw new SignerInitializationException("can not found sign class!", e.getCause()); } else if (WorkMode.STUB.equals(mode)) { throw new SignerInitializationException("can not found extract class", e.getCause()); } } } return clazz; }
From source file:com.aliyun.openservices.odps.console.utils.CommandParserUtils.java
private static AbstractCommand reflectCommandObject(String commandName, Class<?>[] argTypes, Object... args) throws ODPSConsoleException { Class<?> commandClass = null; try {//from www . ja va2 s.c om if (classLoader == null) { loadPlugins(); } commandClass = Class.forName(commandName, false, classLoader); Method parseMethod = commandClass.getDeclaredMethod("parse", argTypes); Object commandObject = parseMethod.invoke(null, args); if (commandObject != null) { return (AbstractCommand) commandObject; } else { return null; } } catch (ClassNotFoundException e) { // Console??AssertionError throw new AssertionError("Cannot find the command:" + commandName); } catch (SecurityException e) { throw new AssertionError("Cannot find the parse method on the command: " + commandName); } catch (NoSuchMethodException e) { //FOR there's two kind of command,not throw exception return null; } catch (IllegalArgumentException e) { throw new AssertionError("Failed to invoke the parse method on the command:" + commandName); } catch (IllegalAccessException e) { throw new AssertionError("Failed to invoke the parse method on the command:" + commandName); } catch (InvocationTargetException e) { if (e.getCause() instanceof ODPSConsoleException) { String msg = e.getCause().getMessage(); if (!StringUtils.isNullOrEmpty(msg) && msg.contains(ODPSConsoleConstants.BAD_COMMAND) && commandClass != null) { String output = getCommandUsageString(commandClass); if (output != null) { throw new ODPSConsoleException(e.getCause().getMessage() + "\n" + output); } } throw (ODPSConsoleException) e.getCause(); } else { throw new ODPSConsoleException(e.getCause()); } } }
From source file:ClassSearchUtils.java
/** * @param name Name of to parent directories in java class notation (dot * separator)/*from w w w .j a va 2s . c om*/ * @param dir Directory to be searched for classes. */ private void lookInDirectory(String name, File dir) { log.fine("Looking in directory [" + dir.getName() + "]."); File[] files = dir.listFiles(); File file; String fileName; final int size = files.length; for (int i = 0; i < size; i++) { file = files[i]; fileName = file.getName(); if (file.isFile() && fileName.toLowerCase().endsWith(this.extension)) { try { if (this.extension.equalsIgnoreCase(".class")) { fileName = fileName.substring(0, fileName.length() - 6); // filter ignored resources if (!(name + fileName).startsWith(this.prefix)) { continue; } log.fine("Found class: [" + name + fileName + "]."); this.list.add(Class.forName(name + fileName)); } else { this.list.add( this.classloader.getResource(name.replace('.', File.separatorChar) + fileName)); } } catch (ClassNotFoundException e) { // ignore } catch (NoClassDefFoundError e) { //ignore too } catch (ExceptionInInitializerError e) { if (e.getCause() instanceof HeadlessException) { // running in headless env ... ignore } else { throw e; } } } // search recursively. // I don't like that but we will see how it will work. if (file.isDirectory()) { lookInDirectory(name + fileName + ".", file); } } }