List of usage examples for java.lang ClassNotFoundException printStackTrace
public void printStackTrace()
From source file:cn.lhfei.hadoop.ch04.PooledStreamCompressor.java
/** * use case: // w w w .j a va 2 s . c o m * * @param args */ public static void main(String[] args) { String codecClassname = args[0]; Class<?> codecClass = null; CompressionOutputStream out = null; Compressor compressor = null; try { codecClass = Class.forName(codecClassname); Configuration conf = new Configuration(); CompressionCodec codec = (CompressionCodec) ReflectionUtils.newInstance(codecClass, conf); compressor = CodecPool.getCompressor(codec); out = codec.createOutputStream(System.out, compressor); IOUtils.copyBytes(System.in, out, 4096, false); out.finish(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { CodecPool.returnCompressor(compressor); } }
From source file:com.hangum.tadpole.engine.procedure.OracleProcedure.java
/** * @param args/*from ww w . j a v a 2 s.c o m*/ */ public static void main(String[] args) { String strQuery = "CREATE OR REPLACE PROCEDURE procOneINOUTParameter(genericParam IN OUT VARCHAR2) " + " IS " + " BEGIN " + " genericParam := 'Hello World INOUT parameter ' || genericParam; " + " END;"; Connection conn = null; Statement stmt = null; try { Class.forName("oracle.jdbc.driver.OracleDriver"); conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.32.128:1521:XE", "HR", "tadpole"); stmt = conn.createStatement(); int code = stmt.executeUpdate(strQuery); System.out.println("[result]" + code); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } finally { try { if (stmt != null) stmt.close(); if (conn != null) conn.close(); } catch (Exception e) { e.printStackTrace(); } } }
From source file:MethodSpy.java
public static void main(String... args) { try {//from ww w . ja va2 s . c o m Class<?> c = Class.forName(args[0]); Method[] allMethods = c.getDeclaredMethods(); for (Method m : allMethods) { if (!m.getName().equals(args[1])) { continue; } out.format("%s%n", m.toGenericString()); out.format(fmt, "ReturnType", m.getReturnType()); out.format(fmt, "GenericReturnType", m.getGenericReturnType()); Class<?>[] pType = m.getParameterTypes(); Type[] gpType = m.getGenericParameterTypes(); for (int i = 0; i < pType.length; i++) { out.format(fmt, "ParameterType", pType[i]); out.format(fmt, "GenericParameterType", gpType[i]); } } // production code should handle these exceptions more gracefully } catch (ClassNotFoundException x) { x.printStackTrace(); } }
From source file:ConstructorTroubleAgain.java
public static void main(String... args) { String argType = (args.length == 0 ? "" : args[0]); try {/*from w ww .jav a 2 s.co m*/ Class<?> c = Class.forName("ConstructorTroubleAgain"); if ("".equals(argType)) { // IllegalArgumentException: wrong number of arguments Object o = c.getConstructor().newInstance("foo"); } else if ("int".equals(argType)) { // NoSuchMethodException - looking for int, have Integer Object o = c.getConstructor(int.class); } else if ("Object".equals(argType)) { // newInstance() does not perform method resolution Object o = c.getConstructor(Object.class).newInstance("foo"); } else { assert false; } // production code should handle these exceptions more gracefully } catch (ClassNotFoundException x) { x.printStackTrace(); } catch (NoSuchMethodException x) { x.printStackTrace(); } catch (InvocationTargetException x) { x.printStackTrace(); } catch (InstantiationException x) { x.printStackTrace(); } catch (IllegalAccessException x) { x.printStackTrace(); } }
From source file:com.predic8.membrane.core.RouterCLI.java
public static void main(String[] args) throws ParseException { MembraneCommandLine cl = new MembraneCommandLine(); cl.parse(args);//from w w w. j a v a2 s .co m if (cl.needHelp()) { cl.printUsage(); return; } try { Router.init(getConfigFile(cl), RouterCLI.class.getClassLoader()).getConfigurationManager() .loadConfiguration(getRulesFile(cl)); //System.out.println("preloading cache..."); //ApplicationCachePreLoader.init(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (PortOccupiedException e) { System.err.println(e.getMessage()); System.exit(1); } catch (Exception ex) { ex.printStackTrace(); System.err.println( "Could not read rules configuration. Please specify a file containing rules using the -c command line option. Or make sure that the file " + System.getenv("MEMBRANE_HOME") + "/conf/rules.xml exists"); System.exit(1); } new RouterCLI().waitForever(); }
From source file:gov.nih.nci.cabig.caaers.tools.ObjectDump.java
public static void main(String[] args) { ObjectDump target = new ObjectDump(); Class cls = null;//from ww w . j av a 2 s. co m Field[] fields; try { cls = Class.forName(target.getClass().getName()); } catch (ClassNotFoundException e) { e.printStackTrace(); } write("Class: " + target.getClass().getName() + "\n"); fields = cls.getFields(); for (int i = 0; i < fields.length; i++) { Field field = fields[i]; write("\tfield[" + (i + 1) + "]: " + field.getName() + "\r\n"); Type type = field.getType(); write(type.toString()); } }
From source file:ArrayCreator.java
public static void main(String... args) { Matcher m = p.matcher(s);/*from w ww.j a v a2s.c om*/ if (m.find()) { String cName = m.group(1); String[] cVals = m.group(2).split("[\\s,]+"); int n = cVals.length; try { Class<?> c = Class.forName(cName); Object o = Array.newInstance(c, n); for (int i = 0; i < n; i++) { String v = cVals[i]; Constructor ctor = c.getConstructor(String.class); Object val = ctor.newInstance(v); Array.set(o, i, val); } Object[] oo = (Object[]) o; out.format("%s[] = %s%n", cName, Arrays.toString(oo)); // production code should handle these exceptions more gracefully } catch (ClassNotFoundException x) { x.printStackTrace(); } catch (NoSuchMethodException x) { x.printStackTrace(); } catch (IllegalAccessException x) { x.printStackTrace(); } catch (InstantiationException x) { x.printStackTrace(); } catch (InvocationTargetException x) { x.printStackTrace(); } } }
From source file:Spy.java
public static void main(String... args) { try {/* w w w . ja v a 2s. c o m*/ Class<?> c = Class.forName(args[0]); int searchMods = 0x0; for (int i = 1; i < args.length; i++) { searchMods |= modifierFromString(args[i]); } Field[] flds = c.getDeclaredFields(); out.format("Fields in Class '%s' containing modifiers: %s%n", c.getName(), Modifier.toString(searchMods)); boolean found = false; for (Field f : flds) { int foundMods = f.getModifiers(); // Require all of the requested modifiers to be present if ((foundMods & searchMods) == searchMods) { out.format("%-8s [ synthetic=%-5b enum_constant=%-5b ]%n", f.getName(), f.isSynthetic(), f.isEnumConstant()); found = true; } } if (!found) { out.format("No matching fields%n"); } // production code should handle this exception more gracefully } catch (ClassNotFoundException x) { x.printStackTrace(); } }
From source file:EnumSpy.java
public static void main(String... args) { try {// w w w . ja v a 2s. co m Class<?> c = Class.forName(args[0]); if (!c.isEnum()) { out.format("%s is not an enum type%n", c); return; } out.format("Class: %s%n", c); Field[] flds = c.getDeclaredFields(); List<Field> cst = new ArrayList<Field>(); // enum constants List<Field> mbr = new ArrayList<Field>(); // member fields for (Field f : flds) { if (f.isEnumConstant()) cst.add(f); else mbr.add(f); } if (!cst.isEmpty()) print(cst, "Constant"); if (!mbr.isEmpty()) print(mbr, "Field"); Constructor[] ctors = c.getDeclaredConstructors(); for (Constructor ctor : ctors) { out.format(fmt, "Constructor", ctor.toGenericString(), synthetic(ctor)); } Method[] mths = c.getDeclaredMethods(); for (Method m : mths) { out.format(fmt, "Method", m.toGenericString(), synthetic(m)); } // production code should handle this exception more gracefully } catch (ClassNotFoundException x) { x.printStackTrace(); } }
From source file:Employee.java
public static void main(String[] args) { Employee e = null;/*w ww .j a v a 2s . c om*/ try { FileInputStream fileIn = new FileInputStream("employee.ser"); ObjectInputStream in = new ObjectInputStream(fileIn); e = (Employee) in.readObject(); in.close(); fileIn.close(); } catch (IOException i) { i.printStackTrace(); return; } catch (ClassNotFoundException c) { System.out.println("Employee class not found"); c.printStackTrace(); return; } System.out.println("Name: " + e.name); System.out.println("Address: " + e.address); System.out.println("SSN: " + e.SSN); System.out.println("Number: " + e.number); }