Example usage for java.lang System exit

List of usage examples for java.lang System exit

Introduction

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

Prototype

public static void exit(int status) 

Source Link

Document

Terminates the currently running Java Virtual Machine.

Usage

From source file:io.ecarf.ccvm.EcarfCcvmTask.java

/**
 * @param args//from   ww  w  .ja  v a 2s  .c o m
 * @throws IOException 
 */
public static void main(String[] args) throws IOException {

    if (args.length != 1) {
        System.out.println("usage EcarfEvmTask <jobConfigJsonFile>");
        System.exit(1);
    }

    Gson gson = new GsonBuilder().setPrettyPrinting().create();

    Coordinator coordinator = null;

    try {

        Job job = Job.fromJsonFile(args[0]);
        log.info("Running job from json file: " + args[0] + ", job id: " + job.getId());
        log.info("Job json: " + gson.toJson(job));
        CloudService cloudService = new EcarfGoogleCloudServiceImpl();
        cloudService.setAuthenticationProvider(new InstanceAuthenticationProvider());
        coordinator = new Coordinator.Builder(job, cloudService).setShutdownProcessors(true).build();

    } catch (IOException e) {
        log.error("Failed to start the coordinator program", e);
        throw e;
    }

    try {
        coordinator.run();
        System.exit(0);

    } catch (Exception e) {
        log.error("Failed to run CCVM", e);
        System.exit(1);
    }
}

From source file:org.echocat.jomon.spring.Boot.java

public static void main(String[] args) {
    if (args == null || (args.length != 1 && args.length != 2)) {
        //noinspection UseOfSystemOutOrSystemErr
        System.err.println("java -cp <?> " + Boot.class.getName()
                + " <boot bean.xml or configuration class name in classpath> [log4j configuration in classpath]");
        //noinspection CallToSystemExit
        System.exit(1);
    } else {//  w ww . j av a2s  . c o m
        final DefaultApplicationRequirement requirement = xmlConfiguredApplicationFor(
                Boot.class.getClassLoader(), args[0]);
        if (args.length > 1) {
            requirement.withLog4jFor(Boot.class.getClassLoader(), args[1]);
        }
        start(requirement);
    }
}

From source file:ca.uqac.info.tag.Counter.TagCounter.java

public static void main(final String[] args) {
    // Parse command line arguments
    Options options = setupOptions();//from w ww .  j av  a  2  s.  c om
    CommandLine c_line = setupCommandLine(args, options);

    String redirectionFile = "";
    String tagAnalyse = "";
    String inputFile = "";

    if (c_line.hasOption("h")) {
        showUsage(options);
        System.exit(ERR_OK);
    }

    //Contains a redirection file for the output
    if (c_line.hasOption("redirection")) {
        try {
            redirectionFile = c_line.getOptionValue("redirection");
            PrintStream ps;
            ps = new PrintStream(redirectionFile);
            System.setOut(ps);
        } catch (FileNotFoundException e) {
            System.out.println("Redirection error !!!");
            e.printStackTrace();
        }
    }

    //Contains a tag
    if (c_line.hasOption("Tag")) {
        tagAnalyse = c_line.getOptionValue("t");
    } else {
        System.err.println("No Tag in Arguments");
        System.exit(ERR_ARGUMENTS);
    }

    //Contains a InputFile 
    if (c_line.hasOption("InputFile")) {
        inputFile = c_line.getOptionValue("i");
    } else {
        System.err.println("No Input File in Arguments");
        System.exit(ERR_ARGUMENTS);
    }

    //Start of the program
    System.out.println("-----------------------------------------------");
    System.out.println("The count of the Tag is start !!!");

    // Throw the Sax parsing for the file 
    try {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser parser;
        parser = factory.newSAXParser();

        File Tagfile = new File(inputFile);
        DefaultHandler manager = new SaxTagHandlers(tagAnalyse);
        parser.parse(Tagfile, manager);
    } catch (ParserConfigurationException e) {
        System.out.println("Parser Configuration Exception for Sax !!!");
        e.printStackTrace();

    } catch (SAXException e) {
        System.out.println("Sax Exception during the parsing !!!");
        e.printStackTrace();
    } catch (IOException e) {
        System.out.println("Input/Ouput Exception during the Sax parsing !!!");
        e.printStackTrace();
    }
}

From source file:com.opengamma.component.tool.DbCreateTool.java

/**
 * Main method to run the tool.//from  w w w.  j  av a 2  s.  c o  m
 * 
 * @param args  the arguments, not null
 */
public static void main(String[] args) { //CSIGNORE
    boolean success = new DbCreateTool().initAndRun(args, DbToolContext.class);
    System.exit(success ? 0 : 1);
}

From source file:net.sf.housekeeper.ApplicationController.java

/**
 * Starts the Housekeeper application with a Swing GUI.
 * /*from w w  w  . j  a  va  2 s .co  m*/
 * @param args No parameters are used.
 */
public static void main(final String[] args) {
    final int jreVersion = JdkVersion.getMajorJavaVersion();
    final int minVersion = JdkVersion.JAVA_15;
    if (jreVersion < minVersion) {
        LogFactory.getLog(ApplicationController.class).fatal("You need at least JRE 5.0 to run Housekeeper!");
        System.exit(1);
    }

    String rootContextDirectoryClassPath = "/net/sf/housekeeper/config/";
    String startupContextPath = rootContextDirectoryClassPath + "startup-context.xml";
    String applicationContextPath = rootContextDirectoryClassPath + "application-context.xml";
    String domainContextPath = rootContextDirectoryClassPath + "domain-context.xml";
    new ApplicationLauncher(startupContextPath, new String[] { applicationContextPath, domainContextPath });
}

From source file:net.sf.housekeeper.Housekeeper.java

/**
 * Starts the Housekeeper application with a Swing GUI.
 * /*from  w ww  .  ja v a 2  s .  c  om*/
 * @param args "--debug" enables debugging messages.
 */
public static void main(final String[] args) {
    if (!SystemUtils.isJavaVersionAtLeast(140)) {
        LogFactory.getLog(Housekeeper.class).fatal("You need at least JRE 1.4 to run Housekeeper!");
        System.exit(1);
    }
    new Housekeeper(args);
}

From source file:it.crs4.features.ImageToAvro.java

public static void main(String[] args) throws Exception {
    Options opts = new Options();
    CommandLine cmd = null;//from w  ww.  ja v  a 2s.co m
    try {
        cmd = parseCmdLine(opts, args);
    } catch (ParseException e) {
        System.err.println("ERROR: " + e.getMessage());
        System.exit(1);
    }
    String fn = null;
    try {
        fn = cmd.getArgs()[0];
    } catch (ArrayIndexOutOfBoundsException e) {
        HelpFormatter fmt = new HelpFormatter();
        fmt.printHelp("java ImageToAvro IMG_FILE", opts);
        System.exit(2);
    }
    String outDirName = null;
    if (cmd.hasOption("outdir")) {
        outDirName = cmd.getOptionValue("outdir");
        File outDir = new File(outDirName);
        if (!outDir.exists()) {
            boolean ret = outDir.mkdirs();
            if (!ret) {
                System.err.format("ERROR: can't create %s\n", outDirName);
                System.exit(3);
            }
        }
    }

    String name = PathTools.stripext(PathTools.basename(fn));
    ImageReader reader = new ImageReader();
    reader.setId(fn);
    LOGGER.info("Reading from {}", fn);
    BioImgFactory factory = new BioImgFactory(reader);
    int seriesCount = factory.getSeriesCount();

    // FIXME: add support for XY slicing
    String seriesName;
    String outFn;
    for (int i = 0; i < seriesCount; i++) {
        seriesName = String.format("%s_%d", name, i);
        outFn = new File(outDirName, seriesName + ".avro").getPath();
        factory.setSeries(i);
        factory.writeSeries(seriesName, outFn);
        LOGGER.info("Writing to {}", outFn);
    }
    reader.close();
    LOGGER.info("All done");
}

From source file:Submenu.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    JMenuBar menubar = new JMenuBar();
    ImageIcon iconNew = new ImageIcon("new.png");
    ImageIcon iconOpen = new ImageIcon("open.png");
    ImageIcon iconSave = new ImageIcon("save.png");
    ImageIcon iconClose = new ImageIcon("exit.png");

    JMenu file = new JMenu("File");
    JMenu imp = new JMenu("Import");

    JMenuItem fileNew = new JMenuItem("New", iconNew);
    JMenuItem fileOpen = new JMenuItem("Open", iconOpen);
    JMenuItem fileSave = new JMenuItem("Save", iconSave);
    JMenuItem fileClose = new JMenuItem("Close", iconClose);

    file.setMnemonic(KeyEvent.VK_F);
    imp.setMnemonic(KeyEvent.VK_M);

    JMenuItem newsf = new JMenuItem("Import newsfeed list...");
    JMenuItem bookm = new JMenuItem("Import bookmarks...");
    JMenuItem mail = new JMenuItem("Import mail...");

    imp.add(newsf);//from w ww  .j  ava  2  s.  c om
    imp.add(bookm);
    imp.add(mail);

    fileNew.setMnemonic(KeyEvent.VK_N);
    fileNew.setMnemonic(KeyEvent.VK_O);
    fileSave.setMnemonic(KeyEvent.VK_S);

    fileClose.setMnemonic(KeyEvent.VK_C);
    fileClose.setToolTipText("Exit application");
    fileClose.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, ActionEvent.CTRL_MASK));

    fileClose.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    });

    file.add(fileNew);
    file.add(fileOpen);
    file.add(fileSave);
    file.addSeparator();
    file.add(imp);
    file.addSeparator();
    file.add(fileClose);

    menubar.add(file);

    f.setJMenuBar(menubar);

    f.setSize(360, 250);
    f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:edu.jhu.hlt.concrete.ingesters.gigaword.GigawordGzProcessor.java

public static void main(String... args) {
    Thread.setDefaultUncaughtExceptionHandler(new LoggedUncaughtExceptionHandler());
    if (args.length != 2) {
        LOGGER.info("This program takes 2 arguments.");
        LOGGER.info("First: the path to a .gz file that is part of the English Gigaword v5 corpus.");
        LOGGER.info("Second: the path to the output file (a .tar.gz with communication files).");
        LOGGER.info("Example usage:");
        LOGGER.info("{} {} {}", GigawordGzProcessor.class.getName(), "/path/to/LDC/sgml/.gz",
                "/path/to/out.tar.gz");
        System.exit(1);
    }//from  www .j av  a2 s  . c om

    String inPathStr = args[0];
    String outPathStr = args[1];

    Path inPath = Paths.get(inPathStr);
    if (!Files.exists(inPath))
        LOGGER.error("Input path {} does not exist. Try again with the right path.", inPath.toString());

    Path outPath = Paths.get(outPathStr);
    Optional<Path> parent = Optional.ofNullable(outPath.getParent());
    // lambda does not allow caught exceptions.
    if (parent.isPresent()) {
        if (!Files.exists(outPath.getParent())) {
            LOGGER.info("Attempting to create output directory: {}", outPath.toString());
            try {
                Files.createDirectories(outPath);
            } catch (IOException e) {
                LOGGER.error("Caught exception creating output directory.", e);
            }
        }
    }

    GigawordDocumentConverter conv = new GigawordDocumentConverter();
    Iterator<Communication> iter = conv.gzToStringIterator(inPath);
    try (OutputStream os = Files.newOutputStream(outPath);
            BufferedOutputStream bos = new BufferedOutputStream(os, 1024 * 8 * 16);
            GzipCompressorOutputStream gout = new GzipCompressorOutputStream(bos);
            TarArchiver archiver = new TarArchiver(gout);) {
        while (iter.hasNext()) {
            Communication c = iter.next();
            LOGGER.info("Adding Communication {} [UUID: {}] to archive.", c.getId(),
                    c.getUuid().getUuidString());
            archiver.addEntry(new ArchivableCommunication(c));
        }
    } catch (IOException e) {
        LOGGER.error("Caught IOException during output.", e);
    }
}

From source file:edu.cuhk.hccl.Application.java

public static void main(String[] args) {

    SpringApplication.run(Application.class, args);

    try {/*from  w w w .  j a  va 2  s  .c  o m*/
        Indexer.createIndex(DATASET_PATH);
    } catch (IOException e) {
        System.out.println("Unable to find the dataset: " + DATASET_PATH);
        System.exit(-1);
    }
}