Example usage for java.lang RuntimeException RuntimeException

List of usage examples for java.lang RuntimeException RuntimeException

Introduction

In this page you can find the example usage for java.lang RuntimeException RuntimeException.

Prototype

public RuntimeException(Throwable cause) 

Source Link

Document

Constructs a new runtime exception with the specified cause and a detail message of (cause==null ?

Usage

From source file:br.com.ant.system.app.AntSystemApp.java

public static void main(String[] args) {

    try {/*from w  w w.j  a  v a2s  . co m*/
        if (SystemUtils.IS_OS_WINDOWS) {
            UIManager.setLookAndFeel(WindowsClassicLookAndFeel.class.getName());
        } else {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }

        ColoniaFormigasView frame = new ColoniaFormigasView();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice[] devices = env.getScreenDevices();

        DisplayMode mode = devices[0].getDisplayMode();
        int height = mode.getHeight();
        int width = mode.getWidth();

        frame.setSize(width, height - 30);
        frame.setVisible(true);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.doctor.ganymed_ssh2.Basic.java

/**
 * Password authentication fails, I get "Authentication method password
 * not supported by the server at this stage
 * /*w  w  w  .j  a v a2s  .com*/
 * ssh? /ect/ssh/sshd_config  ? "PasswordAuthentication"  "no" .
 * changed it to "PasswordAuthentication yes"
 * 
 * 
 * @param args
 * @throws IOException
 */
public static void main(String[] args) throws IOException {
    String hostname = "127.0.0.1";
    String username = "doctor";
    String passwd = "xxx";
    Connection connection = new Connection(hostname);
    connection.connect();

    boolean authenticateWithPassword = connection.authenticateWithPassword(username, passwd);
    if (!authenticateWithPassword) {
        throw new RuntimeException("authenticateWithPassword failed");
    }

    Session session = connection.openSession();
    session.execCommand("pwd  ; date ;echo hello doctor");
    InputStream streamGobbler = new StreamGobbler(session.getStdout());

    String result = IOUtils.toString(streamGobbler, StandardCharsets.UTF_8);
    System.out.println("result:" + result);
    System.out.println("ExitStatus:" + session.getExitStatus());

    session.close();
    connection.close();

}

From source file:sim.app.sugarscape.SugarscapeWithUIHigh.java

public static void main(String[] args) {
    ParameterDatabase parameters = null;
    for (int x = 0; x < args.length - 1; x++)
        if (args[x].equals("-file")) {
            try {
                InputStream is = Class.forName(sim.app.sugarscape.SugarscapeWithUIHigh.class.getCanonicalName())
                        .getClassLoader().getResourceAsStream(args[x + 1]);
                parameters = new ParameterDatabase(is);
            } catch (Exception ex) {
                ex.printStackTrace(System.err);
            }// ww  w  .  j a va2 s. c  om
            break;
        }
    if (parameters == null) {
        throw new RuntimeException(
                "No parameter file was provided.  You need to include it with the arguments:\n\n\t-file myparameters.conf");
    }
    SugarscapeWithUIHigh t = new SugarscapeWithUIHigh(parameters);
    Console c = new Console(t);
    t.console = c;
    c.setVisible(true);
}

From source file:no.uib.tools.OnthologyHttpClient.java

public static void main(String[] args) {
    try {//from w  ww.  jav a 2 s.  co m
        CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpGet getRequest = new HttpGet(
                "http://www.ebi.ac.uk/ols/api/ontologies/mod/terms/http%253A%252F%252Fpurl.obolibrary.org%252Fobo%252FMOD_00861/descendants?size=2002");
        getRequest.addHeader("accept", "application/json");

        HttpResponse response = httpClient.execute(getRequest);

        if (response.getStatusLine().getStatusCode() != 200) {
            throw new RuntimeException("Failed to get the PSIMOD onthology : HTTP error code : "
                    + response.getStatusLine().getStatusCode());
        }

        BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));

        String output;
        FileWriter fw = new FileWriter("./mod.json");
        System.out.println("Output from Server .... \n");
        while ((output = br.readLine()) != null) {
            System.out.println(output);
            fw.write(output);
        }

        fw.close();
        httpClient.close();

    } catch (ClientProtocolException e) {

        e.printStackTrace();

    } catch (IOException e) {

        e.printStackTrace();
    }

}

From source file:com.rk.grid.cluster.slave.NodeMain.java

@SuppressWarnings("unchecked")
public static void main(String[] args) throws IOException {
    String host = "localhost";
    String port = null;//from www . j  a v  a2s.  c o m
    int indx = 0;
    String serviceName = null;
    System.out.println("Node bootstrap params: " + Arrays.asList(args));
    while (indx < args.length && args[indx].startsWith("-")) {
        if (args[indx].equalsIgnoreCase("-p")) {
            port = args[++indx];
            log("Port=" + port);
        } else if (args[indx].equalsIgnoreCase("-h")) {
            host = args[++indx];
            log("Host=" + host);
        } else if (args[indx].equalsIgnoreCase("-b")) {
            serviceName = args[++indx];
            log("Broker ServiceName=" + serviceName);
        }
        indx++;
    }

    if (port == null) {
        throw new RuntimeException("Port not set");
    }

    if (serviceName == null) {
        throw new RuntimeException("Broker Service Name not set");
    }

    RmiProxyFactoryBean s = new RmiProxyFactoryBean();
    s.setServiceUrl("rmi://" + host + ":" + port + "/" + serviceName);
    s.setServiceInterface(IBroker.class);
    s.afterPropertiesSet();

    IBroker<Object> broker = (IBroker<Object>) s.getObject();

    RemoteExecutorNode<Object> remoteExecutor = new RemoteExecutorNode<Object>(broker);

    GridConfig gridConfig = broker.getBrokerInfo().getConfig();

    if (gridConfig.libraryPathDefined()) {
        String libraryPath = gridConfig.getLibraryPath();
        ClassLoader loader = getClassLoader(libraryPath);
        Thread.currentThread().setContextClassLoader(loader);
    }

    InjectionInterceptor interceptor = new InjectionInterceptor();

    if (gridConfig.injectionContextDefined()) {
        String injectionContext = gridConfig.getInjectionContext();
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(injectionContext);
        interceptor.setContext(ctx);
    }

    interceptor.addBean("monitor", broker.getProgressMonitor());

    remoteExecutor.add(interceptor);

    remoteExecutor.start();
}

From source file:siia.jms.MessageListenerContainerDemo.java

public static void main(String[] args) {
    // establish common resources
    ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost");
    Destination queue = new ActiveMQQueue("siia.queue");
    // setup and start listener container
    DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
    container.setConnectionFactory(connectionFactory);
    container.setDestination(queue);//  w w w  .j  a  v  a2 s  .c  om
    container.setMessageListener(new MessageListener() {
        public void onMessage(Message message) {
            try {
                if (!(message instanceof TextMessage)) {
                    throw new IllegalArgumentException("expected TextMessage");
                }
                System.out.println("received: " + ((TextMessage) message).getText());
            } catch (JMSException e) {
                throw new RuntimeException(e);
            }
        }
    });
    container.afterPropertiesSet();
    container.start();
    // send Message
    JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
    jmsTemplate.setDefaultDestination(queue);
    jmsTemplate.convertAndSend("Hello World");
}

From source file:io.stallion.plugins.javascript.JavascriptShell.java

public static void main(String[] args) {
    try {//from  w  ww . j  av a  2s .  c  o m
        new JavascriptShell().runShell(args);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (ScriptException e) {
        throw new RuntimeException(e);
    }
}

From source file:backtype.storm.command.list.java

/**
 * @param args// w  w w .ja  v  a 2 s  .co  m
 */
public static void main(String[] args) {

    NimbusClient client = null;
    try {

        Map conf = Utils.readStormConfig();
        client = NimbusClient.getConfiguredClient(conf);

        if (args.length > 0 && StringUtils.isBlank(args[0]) == false) {
            String topologyName = args[0];
            TopologyInfo info = client.getClient().getTopologyInfoByName(topologyName);

            System.out.println("Successfully get topology info \n" + Utils.toPrettyJsonString(info));
        } else {
            ClusterSummary clusterSummary = client.getClient().getClusterInfo();

            System.out.println("Successfully get cluster info \n" + Utils.toPrettyJsonString(clusterSummary));
        }

    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
        throw new RuntimeException(e);
    } finally {
        if (client != null) {
            client.close();
        }
    }
}

From source file:com.linkedin.python.importer.ImporterCLI.java

public static void main(String[] args) throws Exception {

    Options options = createOptions();/*from   w  ww .ja  va 2s  . c o  m*/

    CommandLineParser parser = new DefaultParser();
    CommandLine line = parser.parse(options, args);

    if (line.hasOption("quite")) {
        Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
        root.setLevel(Level.WARN);
    }

    final File repoPath = new File(line.getOptionValue("repo"));
    final DependencySubstitution replacements = new DependencySubstitution(buildSubstitutionMap(line));

    repoPath.mkdirs();

    if (!repoPath.exists() || !repoPath.isDirectory()) {
        throw new RuntimeException(
                "Unable to continue, " + repoPath.getAbsolutePath() + " does not exist, or is not a directory");
    }

    for (String dependency : line.getArgList()) {
        new DependencyDownloader(dependency, repoPath, replacements).download();
    }

    logger.info("Execution Finished!");
}

From source file:com.virtualparadigm.packman.cli.Main.java

public static void main(String[] args) {
    if (args.length > 0) {
        CommandLineParser cliParser = new BasicParser();
        CommandLine cmd = null;// w  w w  .  j a v  a 2s .  c om
        try {
            cmd = cliParser.parse(Main.buildCommandLineOptions(), args);
        } catch (ParseException pe) {
            throw new RuntimeException(pe);
        }
        if (cmd != null) {
            boolean status = false;
            if (CMD_CREATE.equalsIgnoreCase(args[0])) {
                status = JPackageManager.createPackage(cmd.getOptionValue(CMD_OPTION_LONG_PACKAGE_NAME),
                        cmd.getOptionValue(CMD_OPTION_LONG_PACKAGE_VERSION),
                        new File(cmd.getOptionValue(CMD_OPTION_LONG_PACKAGE_FILE)),
                        new File(cmd.getOptionValue(CMD_OPTION_LONG_OLD_STATE_DIR)),
                        new File(cmd.getOptionValue(CMD_OPTION_LONG_NEW_STATE_DIR)),
                        new File(cmd.getOptionValue(CMD_OPTION_LONG_LICENSE_FILE)),
                        new File(cmd.getOptionValue(CMD_OPTION_LONG_AUTORUN_INSTALL_DIR)),
                        new File(cmd.getOptionValue(CMD_OPTION_LONG_AUTORUN_UNINSTALL_DIR)),
                        (cmd.getOptionValue(CMD_OPTION_LONG_TEMP_DIR) == null) ? null
                                : new File(cmd.getOptionValue(CMD_OPTION_LONG_TEMP_DIR)),
                        (cmd.getOptionValue(CMD_OPTION_LONG_DEV_MODE) != null)
                                ? Boolean.valueOf(cmd.getOptionValue(CMD_OPTION_LONG_DEV_MODE))
                                : false);

                if (status) {
                    System.out.println("Package creation successful");
                } else {
                    System.out.println("Package creation failed");
                }
            } else if (CMD_INSTALL.equalsIgnoreCase(args[0])) {
                status = JPackageManager.installPackage(
                        new File(cmd.getOptionValue(CMD_OPTION_LONG_PACKAGE_FILE)),
                        new File(cmd.getOptionValue(CMD_OPTION_LONG_TARGET_DIR)),
                        new File(cmd.getOptionValue(CMD_OPTION_LONG_DATA_DIR)),
                        new File(cmd.getOptionValue(CMD_OPTION_LONG_LOCAL_CONFIG_FILE)),
                        (cmd.getOptionValue(CMD_OPTION_LONG_DEV_MODE) != null)
                                ? Boolean.valueOf(cmd.getOptionValue(CMD_OPTION_LONG_DEV_MODE))
                                : false);

                if (status) {
                    System.out.println("Package installation successful");
                } else {
                    System.out.println("Package installation failed");
                }

            } else if (CMD_LIST.equalsIgnoreCase(args[0])) {
                System.out.println("Installed Packages");
                System.out.println("");
                Collection<Package> installedPackages = JPackageManager.listPackages();
                if (installedPackages != null) {
                    for (Package installedPackage : installedPackages) {
                        System.out.println("package: " + installedPackage.getName());
                        System.out.println("  version: " + installedPackage.getVersion());
                        System.out.println("  timestamp: " + installedPackage.getInstallTimestamp());
                        System.out.println("  root directory: " + installedPackage.getRootDirectory());
                        System.out.println("");
                    }
                }
            } else {
                System.out.println("unsupported JPatchManager operation");
            }
        } else {
            System.out.println("No command specified. Options are:");
            System.out.println("  " + CMD_CREATE);
            System.out.println("  " + CMD_INSTALL);
            System.out.println("  " + CMD_LIST);
        }
    }
}