List of usage examples for java.lang Throwable printStackTrace
public void printStackTrace()
From source file:com.netxforge.oss2.core.utilsII.ExecRunner.java
/** * This is for unit testing of the class. * * @param args/* w w w. ja va 2 s . c o m*/ * an array of command-line arguments * @throws java.io.IOException * thrown if a problem occurs */ public static void main(final String[] args) throws IOException { try { final ExecRunner er = new ExecRunner(); // /////////////////////////////////////////////////////////////////// // Windows: Test the exec operation with just STDOUT and STDERR System.out.println("Testing ExecRunner with StringWriter..."); er.setMaxRunTimeSecs(1); er.exec("dir /s c:\\"); // er.exec("ls -l"); System.out.println("<STDOUT>\n" + er.getOutString() + "</STDOUT>"); System.out.println("<STDERR>\n" + er.getErrString() + "</STDERR>"); System.out.println("Testing Done"); // /////////////////////////////////////////////////////////////////// // Exit nicely System.exit(0); } catch (final Throwable e) { e.printStackTrace(); System.exit(1); } }
From source file:com.asprise.imaging.core.Imaging.java
public static void main(String[] args) { if (args == null) { args = new String[0]; }//ww w . j av a2 s .co m // Try UI mode if possible try { if (!(args.length > 0 && "console".equalsIgnoreCase(args[args.length - 1])) && !java.awt.GraphicsEnvironment.isHeadless()) { Class<?> cls = Class.forName("com.asprise.imaging.scan.ui.workbench.demo.FrameScanDemo"); Method meth = cls.getMethod("main", String[].class); String[] params = null; // init params accordingly meth.invoke(null, (Object) args); // static method doesn't have an instance return; } } catch (Throwable e) { e.printStackTrace(); } String copyright = "Copyright Asprise, " + Calendar.getInstance().get(Calendar.YEAR) + ". All Rights Reserved. Visit www.asprise.com"; String version = "Library version: " + getLibraryVersion(); try { JOptionPane.showMessageDialog(null, version, copyright, JOptionPane.OK_OPTION | JOptionPane.INFORMATION_MESSAGE); } catch (Throwable t) { // ignore exception } System.out.println(copyright); System.out.println(version); System.out.println(Utils.getEnvInfo(false)); }
From source file:ExecSQL.java
public static void main(String args[]) { try {//from w w w . j a v a 2 s . c o m Scanner in; if (args.length == 0) in = new Scanner(System.in); else in = new Scanner(new File(args[0])); Connection conn = getConnection(); try { Statement stat = conn.createStatement(); while (true) { if (args.length == 0) System.out.println("Enter command or EXIT to exit:"); if (!in.hasNextLine()) return; String line = in.nextLine(); if (line.equalsIgnoreCase("EXIT")) return; if (line.trim().endsWith(";")) // remove trailing semicolon { line = line.trim(); line = line.substring(0, line.length() - 1); } try { boolean hasResultSet = stat.execute(line); if (hasResultSet) showResultSet(stat); } catch (SQLException ex) { for (Throwable e : ex) e.printStackTrace(); } } } finally { conn.close(); } } catch (SQLException e) { for (Throwable t : e) t.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.aol.advertising.qiao.bootstrap.Bootstrap.java
/** * @param args//from w w w . j a v a 2s .c o m */ public static void main(String[] args) { registerShutdownHook(); appCtx = new ClassPathXmlApplicationContext(springContext); try { bootstrap = ContextUtils.getBean(Bootstrap.class); bootstrap.init(); bootstrap.start(); } catch (Throwable e) { System.err.println("Failed to start:" + e.getMessage()); e.printStackTrace(); } }
From source file:com.jredrain.startup.Bootstrap.java
public static void main(String[] args) { if (daemon == null) { daemon = new Bootstrap(); }/* w w w .ja v a2 s .co m*/ try { if (isEmpty(args)) { logger.warn("Bootstrap: error,usage start|stop"); } else { String command = args[0]; if ("start".equals(command)) { daemon.init(); daemon.start(); /** * await for shundown */ daemon.await(); daemon.stopServer(); } else if ("stop".equals(command)) { daemon.shutdown(); } else { logger.warn("Bootstrap: command \"" + command + "\" does not exist."); } } } catch (Throwable t) { if (t instanceof InvocationTargetException && t.getCause() != null) { t = t.getCause(); } handleThrowable(t); t.printStackTrace(); System.exit(1); } }
From source file:fedora.server.utilities.rebuild.Rebuild.java
public static void main(String[] args) { // tell commons-logging to use log4j System.setProperty("org.apache.commons.logging.LogFactory", "org.apache.commons.logging.impl.Log4jFactory"); System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger"); // log4j/* ww w. j a v a2s.co m*/ // File log4jConfig = new File(new File(homeDir), "config/log4j.xml"); // DOMConfigurator.configure(log4jConfig.getPath()); String profile = null; if (args.length > 0) { profile = args[0]; } if (args.length > 1) { fail("Too many arguments", true, true); } try { File serverDir = new File(new File(Constants.FEDORA_HOME), "server"); ServerConfiguration serverConfig = getServerConfig(serverDir, profile); System.err.println(); System.err.println(" Fedora Rebuild Utility"); System.err.println(" .........................."); System.err.println(); System.err.println("WARNING: Live rebuilds are not currently supported."); System.err.println(" Make sure your server is stopped before continuing."); System.err.println(); System.err.println("Server directory is " + serverDir.toString()); if (profile != null) { System.err.print("Server profile is " + profile); } System.err.println(); System.err.println("---------------------------------------------------------------------"); System.err.println(); Rebuilder rebuilder = getRebuilder(); Map<String, String> options = getUserInput(rebuilder, serverDir, serverConfig); new Rebuild(rebuilder, options, serverConfig); } catch (Throwable th) { String msg = th.getMessage(); if (msg == null) { msg = th.getClass().getName(); } fail(msg, false, false); th.printStackTrace(); } }
From source file:com.amazonaws.services.iot.demo.danbo.rpi.Danbo.java
public static void main(String[] args) throws Exception { log.debug("starting"); // uses pin 6 for the red Led final Led redLed = new Led(6); // uses pin 26 for the green Led final Led greenLed = new Led(26); // turns the red led on initially redLed.on();//from w w w. j a v a2 s. c o m // turns the green led off initially greenLed.off(); // loads properties from danbo.properties file - make sure this file is // available on the pi's home directory InputStream input = new FileInputStream("/home/pi/danbo/danbo.properties"); Properties properties = new Properties(); properties.load(input); endpoint = properties.getProperty("awsiot.endpoint"); rootCA = properties.getProperty("awsiot.rootCA"); privateKey = properties.getProperty("awsiot.privateKey"); certificate = properties.getProperty("awsiot.certificate"); url = protocol + endpoint + ":" + port; log.debug("properties loaded"); // turns off both eyes RGBLed rgbLed = new RGBLed("RGBLed1", Danbo.pinLayout1, Danbo.pinLayout2, new Color(0, 0, 0), new Color(0, 0, 0), 0, 100); new Thread(rgbLed).start(); // resets servo to initial positon Servo servo = new Servo("Servo", 1); new Thread(servo).start(); // gets the Pi serial number and uses it as part of the thing // registration name clientId = clientId + getSerialNumber(); // AWS IoT things shadow topics updateTopic = "$aws/things/" + clientId + "/shadow/update"; deltaTopic = "$aws/things/" + clientId + "/shadow/update/delta"; rejectedTopic = "$aws/things/" + clientId + "/shadow/update/rejected"; // AWS IoT controller things shadow topic (used to register new things) controllerUpdateTopic = "$aws/things/Controller/shadow/update"; // defines an empty danbo shadow POJO final DanboShadow danboShadow = new DanboShadow(); DanboShadow.State state = danboShadow.new State(); final DanboShadow.State.Reported reported = state.new Reported(); reported.setEyes("readyToBlink"); reported.setHead("readyToMove"); reported.setMouth("readyToSing"); reported.setName(clientId); state.setReported(reported); danboShadow.setState(state); // defines an empty controller shadow POJO final ControllerShadow controllerShadow = new ControllerShadow(); ControllerShadow.State controllerState = controllerShadow.new State(); final ControllerShadow.State.Reported controllerReported = controllerState.new Reported(); controllerReported.setThingName(clientId); controllerState.setReported(controllerReported); controllerShadow.setState(controllerState); try { log.debug("registering"); // registers the thing (creates a new thing) by updating the // controller String message = gson.toJson(controllerShadow); MQTTPublisher controllerUpdatePublisher = new MQTTPublisher(controllerUpdateTopic, qos, message, url, clientId + "-controllerupdate" + rand.nextInt(100000), cleanSession, rootCA, privateKey, certificate); new Thread(controllerUpdatePublisher).start(); log.debug("registered"); // clears the thing status (in case the thing already existed) Danbo.deleteStatus("initialDelete"); // creates an MQTT subscriber to the things shadow delta topic // (command execution notification) MQTTSubscriber deltaSubscriber = new MQTTSubscriber(new DanboShadowDeltaCallback(), deltaTopic, qos, url, clientId + "-delta" + rand.nextInt(100000), cleanSession, rootCA, privateKey, certificate); new Thread(deltaSubscriber).start(); // creates an MQTT subscriber to the things shadow error topic MQTTSubscriber errorSubscriber = new MQTTSubscriber(new DanboShadowRejectedCallback(), rejectedTopic, qos, url, clientId + "-rejected" + rand.nextInt(100000), cleanSession, rootCA, privateKey, certificate); new Thread(errorSubscriber).start(); // turns the red LED off redLed.off(); ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor(); exec.scheduleAtFixedRate(new Runnable() { @Override public void run() { // turns the green LED on greenLed.on(); log.debug("running publish state thread"); int temp = -300; int humid = -300; reported.setTemperature(new Integer(temp).toString()); reported.setHumidity(new Integer(humid).toString()); try { // reads the temperature and humidity data Set<Sensor> sensors = Sensors.getSensors(); log.debug(sensors.size()); for (Sensor sensor : sensors) { log.debug(sensor.getPhysicalQuantity()); log.debug(sensor.getValue()); if (sensor.getPhysicalQuantity().toString().equals("Temperature")) { temp = sensor.getValue().intValue(); } if (sensor.getPhysicalQuantity().toString().equals("Humidity")) { humid = sensor.getValue().intValue(); } } log.debug("temperature: " + temp); log.debug("humidity: " + humid); reported.setTemperature(new Integer(temp).toString()); reported.setHumidity(new Integer(humid).toString()); } catch (Exception e) { log.error("an error has ocurred: " + e.getMessage()); e.printStackTrace(); } try { // reports current state - last temperature and humidity // read String message = gson.toJson(danboShadow); MQTTPublisher updatePublisher = new MQTTPublisher(updateTopic, qos, message, url, clientId + "-update" + rand.nextInt(100000), cleanSession, rootCA, privateKey, certificate); new Thread(updatePublisher).start(); } catch (Exception e) { log.error("an error has ocurred: " + e.getMessage()); e.printStackTrace(); } // turns the green LED off greenLed.off(); } }, 0, 5, TimeUnit.SECONDS); // runs this thread every 5 seconds, // with an initial delay of 5 seconds } catch (MqttException me) { // Display full details of any exception that occurs log.error("reason " + me.getReasonCode()); log.error("msg " + me.getMessage()); log.error("loc " + me.getLocalizedMessage()); log.error("cause " + me.getCause()); log.error("excep " + me); me.printStackTrace(); } catch (Throwable th) { log.error("msg " + th.getMessage()); log.error("loc " + th.getLocalizedMessage()); log.error("cause " + th.getCause()); log.error("excep " + th); th.printStackTrace(); } }
From source file:com.mgreau.jboss.as7.cli.CliLauncher.java
public static void main(String[] args) throws Exception { int exitCode = 0; CommandContext cmdCtx = null;/*from w ww. jav a 2s. co m*/ boolean gui = false; String appName = ""; try { String argError = null; List<String> commands = null; File file = null; boolean connect = false; String defaultControllerProtocol = "http-remoting"; String defaultControllerHost = null; int defaultControllerPort = -1; boolean version = false; String username = null; char[] password = null; int connectionTimeout = -1; //App deployment boolean isAppDeployment = false; final Properties props = new Properties(); for (String arg : args) { if (arg.startsWith("--controller=") || arg.startsWith("controller=")) { final String fullValue; final String value; if (arg.startsWith("--")) { fullValue = arg.substring(13); } else { fullValue = arg.substring(11); } final int protocolEnd = fullValue.lastIndexOf("://"); if (protocolEnd == -1) { value = fullValue; } else { value = fullValue.substring(protocolEnd + 3); defaultControllerProtocol = fullValue.substring(0, protocolEnd); } String portStr = null; int colonIndex = value.lastIndexOf(':'); if (colonIndex < 0) { // default port defaultControllerHost = value; } else if (colonIndex == 0) { // default host portStr = value.substring(1); } else { final boolean hasPort; int closeBracket = value.lastIndexOf(']'); if (closeBracket != -1) { //possible ip v6 if (closeBracket > colonIndex) { hasPort = false; } else { hasPort = true; } } else { //probably ip v4 hasPort = true; } if (hasPort) { defaultControllerHost = value.substring(0, colonIndex).trim(); portStr = value.substring(colonIndex + 1).trim(); } else { defaultControllerHost = value; } } if (portStr != null) { int port = -1; try { port = Integer.parseInt(portStr); if (port < 0) { argError = "The port must be a valid non-negative integer: '" + args + "'"; } else { defaultControllerPort = port; } } catch (NumberFormatException e) { argError = "The port must be a valid non-negative integer: '" + arg + "'"; } } } else if ("--connect".equals(arg) || "-c".equals(arg)) { connect = true; } else if ("--version".equals(arg)) { version = true; } else if ("--gui".equals(arg)) { gui = true; } else if (arg.startsWith("--appDeployment=") || arg.startsWith("appDeployment=")) { isAppDeployment = true; appName = arg.startsWith("--") ? arg.substring(16) : arg.substring(14); } else if (arg.startsWith("--file=") || arg.startsWith("file=")) { if (file != null) { argError = "Duplicate argument '--file'."; break; } if (commands != null) { argError = "Only one of '--file', '--commands' or '--command' can appear as the argument at a time."; break; } final String fileName = arg.startsWith("--") ? arg.substring(7) : arg.substring(5); if (!fileName.isEmpty()) { file = new File(fileName); if (!file.exists()) { argError = "File " + file.getAbsolutePath() + " doesn't exist."; break; } } else { argError = "Argument '--file' is missing value."; break; } } else if (arg.startsWith("--commands=") || arg.startsWith("commands=")) { if (file != null) { argError = "Only one of '--file', '--commands' or '--command' can appear as the argument at a time."; break; } if (commands != null) { argError = "Duplicate argument '--command'/'--commands'."; break; } final String value = arg.startsWith("--") ? arg.substring(11) : arg.substring(9); commands = Util.splitCommands(value); } else if (arg.startsWith("--command=") || arg.startsWith("command=")) { if (file != null) { argError = "Only one of '--file', '--commands' or '--command' can appear as the argument at a time."; break; } if (commands != null) { argError = "Duplicate argument '--command'/'--commands'."; break; } final String value = arg.startsWith("--") ? arg.substring(10) : arg.substring(8); commands = Collections.singletonList(value); } else if (arg.startsWith("--user=")) { username = arg.startsWith("--") ? arg.substring(7) : arg.substring(5); } else if (arg.startsWith("--password=")) { password = (arg.startsWith("--") ? arg.substring(11) : arg.substring(9)).toCharArray(); } else if (arg.startsWith("--timeout=")) { if (connectionTimeout > 0) { argError = "Duplicate argument '--timeout'"; break; } final String value = arg.substring(10); try { connectionTimeout = Integer.parseInt(value); } catch (final NumberFormatException e) { // } if (connectionTimeout <= 0) { argError = "The timeout must be a valid positive integer: '" + value + "'"; } } else if (arg.equals("--help") || arg.equals("-h")) { commands = Collections.singletonList("help"); } else if (arg.startsWith("--properties=")) { final String value = arg.substring(13); final File propertiesFile = new File(value); if (!propertiesFile.exists()) { argError = "File doesn't exist: " + propertiesFile.getAbsolutePath(); break; } FileInputStream fis = null; try { fis = new FileInputStream(propertiesFile); props.load(fis); } catch (FileNotFoundException e) { argError = e.getLocalizedMessage(); break; } catch (java.io.IOException e) { argError = "Failed to load properties from " + propertiesFile.getAbsolutePath() + ": " + e.getLocalizedMessage(); break; } finally { if (fis != null) { try { fis.close(); } catch (java.io.IOException e) { } } } for (final Object prop : props.keySet()) { AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { System.setProperty((String) prop, (String) props.get(prop)); return null; } }); } } else if (!(arg.startsWith("-D") || arg.equals("-XX:"))) {// skip system properties and jvm options // assume it's commands if (file != null) { argError = "Only one of '--file', '--commands' or '--command' can appear as the argument at a time: " + arg; break; } if (commands != null) { argError = "Duplicate argument '--command'/'--commands'."; break; } commands = Util.splitCommands(arg); } } if (argError != null) { System.err.println(argError); exitCode = 1; return; } if (version) { cmdCtx = initCommandContext(defaultControllerProtocol, defaultControllerHost, defaultControllerPort, username, password, false, connect, connectionTimeout); VersionHandler.INSTANCE.handle(cmdCtx); return; } if (file != null) { cmdCtx = initCommandContext(defaultControllerProtocol, defaultControllerHost, defaultControllerPort, username, password, false, connect, connectionTimeout); processFile(file, cmdCtx, isAppDeployment, appName, props); return; } if (commands != null) { cmdCtx = initCommandContext(defaultControllerProtocol, defaultControllerHost, defaultControllerPort, username, password, false, connect, connectionTimeout); processCommands(commands, cmdCtx); return; } // Interactive mode cmdCtx = initCommandContext(defaultControllerProtocol, defaultControllerHost, defaultControllerPort, username, password, true, connect, connectionTimeout); cmdCtx.interact(); } catch (Throwable t) { t.printStackTrace(); exitCode = 1; } finally { if (cmdCtx != null && cmdCtx.getExitCode() != 0) { exitCode = cmdCtx.getExitCode(); } if (!gui) { System.exit(exitCode); } } System.exit(exitCode); }
From source file:com.intuit.tank.tools.script.ScriptFilterRunner.java
/** * @param args/*from w ww. ja v a 2s.c om*/ */ public static void main(String[] args) { try { System.setProperty("jsse.enableSNIExtension", "false"); } catch (Throwable e1) { System.err.println("Error setting property " + e1); e1.printStackTrace(); } String url = "http://localhost:8080/"; if (args.length > 0) { url = args[0]; } new ScriptFilterRunner(true, url).setVisible(true); }
From source file:de.huberlin.wbi.hiway.common.Client.java
/** * The main routine./*w w w . ja v a 2 s . com*/ * * @param args Command line arguments passed to the Client. */ public static void main(String[] args) { boolean result = false; try { Client client = new Client(); try { boolean doRun = client.init(args); if (!doRun) { System.exit(0); } } catch (IllegalArgumentException e) { client.printUsage(); e.printStackTrace(System.out); System.exit(-1); } result = client.run(); } catch (Throwable t) { System.out.println("Error running Client"); t.printStackTrace(); System.exit(-1); } if (result) { System.out.println("Application completed successfully"); System.exit(0); } System.out.println("Application failed"); System.exit(2); }