Example usage for org.apache.commons.cli BasicParser BasicParser

List of usage examples for org.apache.commons.cli BasicParser BasicParser

Introduction

In this page you can find the example usage for org.apache.commons.cli BasicParser BasicParser.

Prototype

BasicParser

Source Link

Usage

From source file:com.hortonworks.registries.storage.tool.sql.TablesInitializer.java

public static void main(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(Option.builder("s").numberOfArgs(1).longOpt(OPTION_SCRIPT_ROOT_PATH)
            .desc("Root directory of script path").build());

    options.addOption(Option.builder("c").numberOfArgs(1).longOpt(OPTION_CONFIG_FILE_PATH)
            .desc("Config file path").build());

    options.addOption(Option.builder("m").numberOfArgs(1).longOpt(OPTION_MYSQL_JAR_URL_PATH)
            .desc("Mysql client jar url to download").build());

    options.addOption(Option.builder().hasArg(false).longOpt(SchemaMigrationOption.CREATE.toString())
            .desc("Run sql migrations from scatch").build());

    options.addOption(Option.builder().hasArg(false).longOpt(SchemaMigrationOption.DROP.toString())
            .desc("Drop all the tables in the target database").build());

    options.addOption(Option.builder().hasArg(false).longOpt(SchemaMigrationOption.CHECK_CONNECTION.toString())
            .desc("Check the connection for configured data source").build());

    options.addOption(Option.builder().hasArg(false).longOpt(SchemaMigrationOption.MIGRATE.toString())
            .desc("Execute schema migration from last check point").build());

    options.addOption(Option.builder().hasArg(false).longOpt(SchemaMigrationOption.INFO.toString())
            .desc("Show the status of the schema migration compared to the target database").build());

    options.addOption(Option.builder().hasArg(false).longOpt(SchemaMigrationOption.VALIDATE.toString())
            .desc("Validate the target database changes with the migration scripts").build());

    options.addOption(Option.builder().hasArg(false).longOpt(SchemaMigrationOption.REPAIR.toString()).desc(
            "Repairs the DATABASE_CHANGE_LOG by removing failed migrations and correcting checksum of existing migration script")
            .build());//from  w  ww.ja v a  2s .  c o m

    options.addOption(Option.builder().hasArg(false).longOpt(DISABLE_VALIDATE_ON_MIGRATE)
            .desc("Disable flyway validation checks while running migrate").build());

    CommandLineParser parser = new BasicParser();
    CommandLine commandLine = parser.parse(options, args);

    if (!commandLine.hasOption(OPTION_CONFIG_FILE_PATH) || !commandLine.hasOption(OPTION_SCRIPT_ROOT_PATH)) {
        usage(options);
        System.exit(1);
    }

    boolean isSchemaMigrationOptionSpecified = false;
    SchemaMigrationOption schemaMigrationOptionSpecified = null;
    for (SchemaMigrationOption schemaMigrationOption : SchemaMigrationOption.values()) {
        if (commandLine.hasOption(schemaMigrationOption.toString())) {
            if (isSchemaMigrationOptionSpecified) {
                System.out.println(
                        "Only one operation can be execute at once, please select one of 'create', ',migrate', 'validate', 'info', 'drop', 'repair', 'check-connection'.");
                System.exit(1);
            }
            isSchemaMigrationOptionSpecified = true;
            schemaMigrationOptionSpecified = schemaMigrationOption;
        }
    }

    if (!isSchemaMigrationOptionSpecified) {
        System.out.println(
                "One of the option 'create', ',migrate', 'validate', 'info', 'drop', 'repair', 'check-connection' must be specified to execute.");
        System.exit(1);
    }

    String confFilePath = commandLine.getOptionValue(OPTION_CONFIG_FILE_PATH);
    String scriptRootPath = commandLine.getOptionValue(OPTION_SCRIPT_ROOT_PATH);
    String mysqlJarUrl = commandLine.getOptionValue(OPTION_MYSQL_JAR_URL_PATH);

    StorageProviderConfiguration storageProperties;
    Map<String, Object> conf;
    try {
        conf = Utils.readConfig(confFilePath);

        StorageProviderConfigurationReader confReader = new StorageProviderConfigurationReader();
        storageProperties = confReader.readStorageConfig(conf);
    } catch (IOException e) {
        System.err.println("Error occurred while reading config file: " + confFilePath);
        System.exit(1);
        throw new IllegalStateException("Shouldn't reach here");
    }

    String bootstrapDirPath = null;
    try {
        bootstrapDirPath = System.getProperty("bootstrap.dir");
        Proxy proxy = Proxy.NO_PROXY;
        String httpProxyUrl = (String) conf.get(HTTP_PROXY_URL);
        String httpProxyUsername = (String) conf.get(HTTP_PROXY_USERNAME);
        String httpProxyPassword = (String) conf.get(HTTP_PROXY_PASSWORD);
        if ((httpProxyUrl != null) && !httpProxyUrl.isEmpty()) {
            URL url = new URL(httpProxyUrl);
            proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(url.getHost(), url.getPort()));
            if ((httpProxyUsername != null) && !httpProxyUsername.isEmpty()) {
                Authenticator.setDefault(getBasicAuthenticator(url.getHost(), url.getPort(), httpProxyUsername,
                        httpProxyPassword));
            }
        }
        MySqlDriverHelper.downloadMySQLJarIfNeeded(storageProperties, bootstrapDirPath, mysqlJarUrl, proxy);
    } catch (Exception e) {
        System.err.println("Error occurred while downloading MySQL jar. bootstrap dir: " + bootstrapDirPath);
        System.exit(1);
        throw new IllegalStateException("Shouldn't reach here");
    }

    boolean disableValidateOnMigrate = commandLine.hasOption(DISABLE_VALIDATE_ON_MIGRATE);
    if (disableValidateOnMigrate) {
        System.out.println("Disabling validation on schema migrate");
    }
    SchemaMigrationHelper schemaMigrationHelper = new SchemaMigrationHelper(
            SchemaFlywayFactory.get(storageProperties, scriptRootPath, !disableValidateOnMigrate));
    try {
        schemaMigrationHelper.execute(schemaMigrationOptionSpecified);
        System.out
                .println(String.format("\"%s\" option successful", schemaMigrationOptionSpecified.toString()));
    } catch (Exception e) {
        System.err.println(
                String.format("\"%s\" option failed : %s", schemaMigrationOptionSpecified.toString(), e));
        System.exit(1);
    }

}

From source file:eu.edisonproject.classification.main.BatchMain.java

public static void main(String[] args) throws Exception {
    try {/*w ww .j  av  a  2s. c  o m*/
        //            args = new String[1];
        //            args[0] = "..";
        //            TestDataFlow.execute(args);
        //            System.exit(0);
        //            TestTFIDF.execute(args);

        Options options = new Options();

        Option operation = new Option("op", "operation", true, "type of operation to perform. "
                + "To convert txt to avro 'a'.\n" + "For running clasification on avro documents 'c'");
        operation.setRequired(true);
        options.addOption(operation);

        Option input = new Option("i", "input", true, "input path");
        input.setRequired(false);
        options.addOption(input);

        Option output = new Option("o", "output", true, "output file");
        output.setRequired(false);
        options.addOption(output);

        Option competencesVector = new Option("c", "competences-vector", true, "competences vectors");
        competencesVector.setRequired(false);
        options.addOption(competencesVector);

        Option v1 = new Option("v1", "vector1", true, "");
        v1.setRequired(false);
        options.addOption(v1);

        Option v2 = new Option("v2", "vector2", true, "");
        v2.setRequired(false);
        options.addOption(v2);

        Option popertiesFile = new Option("p", "properties", true, "path for a properties file");
        popertiesFile.setRequired(false);
        options.addOption(popertiesFile);

        CommandLineParser parser = new BasicParser();
        CommandLine cmd = parser.parse(options, args);
        String propPath = cmd.getOptionValue("properties");
        MyProperties prop;
        if (propPath == null) {
            prop = ConfigHelper
                    .getProperties(".." + File.separator + "etc" + File.separator + "configure.properties");
        } else {
            prop = ConfigHelper.getProperties(propPath);
        }

        switch (cmd.getOptionValue("operation")) {
        case "a":
            text2Avro(cmd.getOptionValue("input"), cmd.getOptionValue("output"), prop);
            break;
        case "c":
            calculateTFIDF(cmd.getOptionValue("input"), cmd.getOptionValue("output"),
                    cmd.getOptionValue("competences-vector"), prop);
            break;
        case "p":
            //                    -op p -v2 $HOME/Downloads/msc.csv -v1 $HOME/Downloads/job.csv -p $HOME/workspace/E-CO-2/etc/classification.properties
            profile(cmd.getOptionValue("v1"), cmd.getOptionValue("v2"), cmd.getOptionValue("output"));
            break;
        }

    } catch (IllegalArgumentException | ParseException | IOException ex) {
        Logger.getLogger(BatchMain.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.versusoft.packages.ooo.odt2daisy.gui.CommandLineGUI.java

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

    Handler fh = new FileHandler(LOG_FILENAME_PATTERN);
    fh.setFormatter(new SimpleFormatter());

    //removeAllLoggersHandlers(Logger.getLogger(""));

    Logger.getLogger("").addHandler(fh);
    Logger.getLogger("").setLevel(Level.FINEST);

    Options options = new Options();

    Option option1 = new Option("in", "name of ODT file (required)");
    option1.setRequired(true);/*from   w  w  w .  ja  v a2 s .com*/
    option1.setArgs(1);

    Option option2 = new Option("out", "name of DAISY DTB file (required)");
    option2.setRequired(true);
    option2.setArgs(1);

    Option option3 = new Option("h", "show this help");
    option3.setArgs(Option.UNLIMITED_VALUES);

    Option option4 = new Option("alt", "use alternate Level Markup");

    Option option5 = new Option("u", "UID of DAISY DTB (optional)");
    option5.setArgs(1);

    Option option6 = new Option("t", "Title of DAISY DTB");
    option6.setArgs(1);

    Option option7 = new Option("c", "Creator of DAISY DTB");
    option7.setArgs(1);

    Option option8 = new Option("p", "Publisher of DAISY DTB");
    option8.setArgs(1);

    Option option9 = new Option("pr", "Producer of DAISY DTB");
    option9.setArgs(1);

    Option option10 = new Option("pic", "set Picture directory");
    option10.setArgs(1);

    Option option11 = new Option("page", "enable pagination");
    option11.setArgs(0);

    Option option12 = new Option("css", "write CSS file");
    option12.setArgs(0);

    options.addOption(option1);
    options.addOption(option2);
    options.addOption(option3);
    options.addOption(option4);
    options.addOption(option5);
    options.addOption(option6);
    options.addOption(option7);
    options.addOption(option8);
    options.addOption(option9);
    options.addOption(option10);
    options.addOption(option11);
    options.addOption(option12);

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = null;

    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        //System.out.println("***ERROR: " + e.getClass() + ": " + e.getMessage());

        printHelp();
        return;
    }

    if (cmd.hasOption("help")) {
        printHelp();
        return;
    }

    try {

        Odt2Daisy odt2daisy = new Odt2Daisy(cmd.getOptionValue("in")); //@todo add initial output directory URL?
        odt2daisy.init();

        if (odt2daisy.isEmptyDocument()) {
            logger.info("Cannot convert empty documents. Export Aborted...");
            System.exit(1);
        }

        //System.out.println("Metadatas");
        //System.out.println("- title: " + odt2daisy.getTitleMeta());
        //System.out.println("- creator: " + odt2daisy.getCreatorMeta());

        if (!odt2daisy.isUsingHeadings()) {
            logger.info("You SHOULD use Heading styles in your document. Export in a single level.");
        }
        //@todo Warning for incompatible image formats should go here. See UnoGui.java.

        if (cmd.hasOption("u")) {
            //System.out.println("arg uid:"+cmd.getOptionValue("u"));
            odt2daisy.setUidParam(cmd.getOptionValue("u"));
        }

        if (cmd.hasOption("t")) {
            //System.out.println("arg title:"+cmd.getOptionValue("t"));
            odt2daisy.setTitleParam(cmd.getOptionValue("t"));
        }

        if (cmd.hasOption("c")) {
            //System.out.println("arg creator:"+cmd.getOptionValue("c"));
            odt2daisy.setCreatorParam(cmd.getOptionValue("c"));
        }

        if (cmd.hasOption("p")) {
            //System.out.println("arg publisher:"+cmd.getOptionValue("p"));
            odt2daisy.setPublisherParam(cmd.getOptionValue("p"));
        }

        if (cmd.hasOption("pr")) {
            //System.out.println("arg producer:"+cmd.getOptionValue("pr"));
            odt2daisy.setProducerParam(cmd.getOptionValue("pr"));
        }

        if (cmd.hasOption("alt")) {
            //System.out.println("arg alt:"+cmd.getOptionValue("alt"));
            odt2daisy.setUseAlternateLevelParam(true);
        }

        if (cmd.hasOption("css")) {
            odt2daisy.setWriteCSSParam(true);
        }

        if (cmd.hasOption("page")) {
            odt2daisy.paginationProcessing();
        }

        odt2daisy.correctionProcessing();

        if (cmd.hasOption("pic")) {

            odt2daisy.convertAsDTBook(cmd.getOptionValue("out"), cmd.getOptionValue("pic"));

        } else {

            logger.info("Language detected: " + odt2daisy.getLangParam());
            odt2daisy.convertAsDTBook(cmd.getOptionValue("out"), Configuration.DEFAULT_IMAGE_DIR);
        }

        boolean valid = odt2daisy.validateDTD(cmd.getOptionValue("out"));

        if (valid) {

            logger.info("DAISY DTBook produced is valid against DTD - Congratulations !");

        } else {

            logger.info("DAISY Book produced isn't valid against DTD - You SHOULD NOT use this DAISY Book !");
            logger.info("Error at line: " + odt2daisy.getErrorHandler().getLineNumber());
            logger.info("Error Message: " + odt2daisy.getErrorHandler().getMessage());
        }

    } catch (Exception e) {

        e.printStackTrace();

    } finally {

        if (fh != null) {
            fh.flush();
            fh.close();
        }
    }

}

From source file:edu.usc.pgroup.floe.flake.FlakeService.java

/**
 * Entry point for the flake./*from w w  w. j av  a 2 s  . c om*/
 *
 * @param args commandline arguments. (TODO)
 */
public static void main(final String[] args) {

    Options options = buildOptions();

    CommandLineParser parser = new BasicParser();
    CommandLine line;
    try {
        line = parser.parse(options, args);

    } catch (ParseException e) {
        LOGGER.error("Invalid command: " + e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("FlakeService", options);
        return;
    }

    String pid = line.getOptionValue("pid");
    String id = line.getOptionValue("id");
    String cid = line.getOptionValue("cid");
    String appName = line.getOptionValue("appname");
    String token = line.getOptionValue("token");
    String jar = null;
    if (line.hasOption("jar")) {
        jar = line.getOptionValue("jar");
    }

    LOGGER.info("pid: {}, id:{}, cid:{}, app:{}, jar:{}", pid, id, cid, appName, jar);
    try {
        new FlakeService(pid, id, cid, appName, jar).start();
    } catch (Exception e) {
        LOGGER.error("Exception while creating flake: {}", e);
        return;
    }
}

From source file:com.metadave.stow.Stow.java

public static void main(String args[]) {
    System.out.println("Stow: StringTemplate Object Wrapper");
    System.out.println("(C) 2014 Dave Parfitt");
    System.out.println("Stow uses the Apache 2 license");

    CommandLineParser parser = new BasicParser();

    Options options = new Options();
    //options.addOption( "a", "all", false, "do not hide entries starting with .");

    Option javaPackage = new Option("java_package", "package for generated classes");
    javaPackage.setArgs(1);//  www  .j av  a2s. c  om
    //javaPackage.setRequired(true);

    Option destDir = new Option("dest", "destination directory for generated .java files");
    destDir.setArgs(1);

    Option stgFile = new Option("stg", "StringTemplate4 group file");
    stgFile.setArgs(1);

    Option classPrefix = new Option("class_prefix", "Prefix to use for generated classes");
    classPrefix.setArgs(1);

    //destDir.setRequired(true);

    options.addOption(javaPackage);
    options.addOption(destDir);
    options.addOption(stgFile);
    options.addOption(classPrefix);

    try {
        CommandLine line = parser.parse(options, args);

        if (line.hasOption("java_package") && line.hasOption("dest") && line.hasOption("stg")) {
            generateObjects(line.getOptionValue("stg"), line.getOptionValue("java_package"),
                    line.hasOption("class_prefix") ? line.getOptionValue("class_prefix") : "",
                    line.getOptionValue("dest"));
        } else {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("stow", options);
        }
    } catch (ParseException exp) {
        System.out.println("Error parsing stow command line:" + exp.getMessage());
    }
}

From source file:mecard.BImportCustomerLoader.java

/**
 * Runs the entire process of loading customer bimport files as a timed 
 * process such as cron or Windows scheduler.
 * @param args /*from www.  ja va 2s  .c  o m*/
 */
public static void main(String args[]) {
    // First get the valid options
    Options options = new Options();
    // add t option c to config directory true=arg required.
    options.addOption("c", true,
            "Configuration file directory path, include all sys dependant dir seperators like '/'.");
    // add v option v for server version.
    options.addOption("v", false, "Metro server version information.");
    options.addOption("d", false, "Outputs debug information about the customer load.");
    options.addOption("U", false,
            "Execute upload of customer accounts, otherwise just cleans up the directory.");
    options.addOption("p", true,
            "Path to PID file. If present back off and wait for reschedule customer load.");
    options.addOption("a", false, "Maximum age of PID file before warning (in minutes).");
    try {
        // parse the command line.
        CommandLineParser parser = new BasicParser();
        CommandLine cmd;
        cmd = parser.parse(options, args);
        if (cmd.hasOption("v")) {
            System.out.println("Metro (MeCard) server version " + PropertyReader.VERSION);
            return; // don't run if user just wants version.
        }
        if (cmd.hasOption("U")) {
            uploadCustomers = true;
        }
        if (cmd.hasOption("p")) // location of the pidFile, default is current directory (relative to jar location).
        {
            pidDir = cmd.getOptionValue("p");
            if (pidDir.endsWith(File.separator) == false) {
                pidDir += File.separator;
            }
        }
        if (cmd.hasOption("d")) // debug.
        {
            debug = true;
        }
        if (cmd.hasOption("a")) {
            try {
                maxPIDAge = Integer.parseInt(cmd.getOptionValue("a"));
            } catch (NumberFormatException e) {
                System.out.println("*Warning: the value used on the '-a' flag, '" + cmd.getOptionValue("a")
                        + "' cannot be " + "converted to an integer and is therefore an illegal value for "
                        + "maximum PID file age. Maximum PID age set to: " + maxPIDAge + " minutes.");
            }
        }
        // get c option value
        String configDirectory = cmd.getOptionValue("c");
        PropertyReader.setConfigDirectory(configDirectory);
        BImportCustomerLoader loader = new BImportCustomerLoader();
        loader.run();
    } catch (ParseException ex) {
        String msg = new Date()
                + "Unable to parse command line option. Please check your service configuration.";
        if (debug) {
            System.out.println("DEBUG: request for invalid command line option.");
        }
        Logger.getLogger(MetroService.class.getName()).log(Level.SEVERE, msg, ex);
        System.exit(899); // 799 for mecard
    } catch (NumberFormatException ex) {
        String msg = new Date() + "Request for invalid -a command line option.";
        if (debug) {
            System.out.println("DEBUG: request for invalid -a command line option.");
            System.out.println("DEBUG: value set to " + maxPIDAge);
        }
        Logger.getLogger(MetroService.class.getName()).log(Level.WARNING, msg, ex);
    }
    System.exit(0);
}

From source file:SearchApiExample.java

/**
* @param args/*  w  w w.  j a v a2  s .  co  m*/
*/
public static void main(String[] args) {
    Options options = buildOptions();
    try {
        CommandLine line = new BasicParser().parse(options, args);
        processCommandLine(line, options);
    } catch (ParseException exp) {
        System.err.println(exp.getMessage());
        printHelp(options);
    }
}

From source file:com.momab.dstool.DSTool.java

public static void main(String[] args) throws ParseException, IOException, ClassNotFoundException {

    final CommandLineParser parser = new BasicParser();
    final Options options = commandLineOptions();
    final CommandLine line = parser.parse(options, args);

    if (args.length == 0) {
        printUsage(options, System.out);
        System.exit(0);/*from   ww w. j ava 2  s .  com*/
    }

    if (args.length == 1 && line.hasOption("h")) {
        printHelp(options, System.out);
        System.exit(0);
    }

    if (!line.hasOption("r") && !line.hasOption("w") && !line.hasOption("d")) {
        printErrorMessage("One of the options -r -w or -d must be specified.", System.err);
        System.exit(-1);
    }

    if (line.getArgs().length != 2) {
        printErrorMessage("To few arguments.", System.err);
        System.exit(-1);
    }

    DSOperation op = null;

    // Required operands/arguments
    DSOperationBuilder opBuilder = new DSOperationBuilder(line.getArgs()[0], line.getArgs()[1]);

    // Username and password
    if (line.hasOption("u") || line.hasOption("p")) {
        if (!line.hasOption("u") || !line.hasOption("p")) {
            printErrorMessage("Missing username or password", System.err);
            System.exit(-1);
        }

        opBuilder.asUser(line.getOptionValue("u"), line.getOptionValue("p"));
    }

    // Port
    if (line.hasOption("P")) {
        opBuilder = opBuilder.usingPort(Integer.valueOf(line.getOptionValue("P")));
    }

    // File
    File file = null;
    OutputStream out = null;
    InputStream in = null;
    if (line.hasOption("f")) {
        if (line.hasOption("d")) {
            printErrorMessage("Option -f is invalid for a -d delete operation", System.err);
            System.exit(-1);
        }

        file = new File(line.getOptionValue("f"));
    }

    // Read (download) operation
    if (line.hasOption("r")) {

        if (file != null) {
            out = new FileOutputStream(file);
        } else {
            out = System.out;
        }

        opBuilder = opBuilder.writeTo(out);

        op = opBuilder.buildDownload();
    }

    // Write (upload) operation
    if (line.hasOption("w")) {

        if (file != null) {
            in = new FileInputStream(file);
        } else {
            in = System.in;
        }

        opBuilder = opBuilder.readFrom(in);

        op = opBuilder.buildUpload();
    }

    // Delete (upload) operation
    if (line.hasOption("d")) {
        op = opBuilder.buildDelete();
    }

    if (file != null || line.hasOption("d")) {
        boolean result = op.Run(new ProgressPrinter() {
        });

        if (in != null)
            in.close();
        if (out != null)
            out.close();

        System.exit(result ? 0 : -1);

    } else {
        System.exit(op.Run(null) ? 0 : -1);
    }

}

From source file:com.boulmier.machinelearning.jobexecutor.JobExecutor.java

public static void main(String[] args) throws ParseException, IOException, InterruptedException {
    Options options = defineOptions();//from   www .  ja  va  2 s.  c  o m
    sysMon = new JavaSysMon();
    InetAddress vmscheduler_ip, mongodb_ip = null;
    Integer vmscheduler_port = null, mongodb_port = null;
    CommandLineParser parser = new BasicParser();

    try {
        CommandLine cmd = parser.parse(options, args);
        if (cmd.hasOption(JobExecutorConfig.OPTIONS.CMD.LONGPORTFIELD)) {
            vmscheduler_port = Integer.valueOf(cmd.getOptionValue(JobExecutorConfig.OPTIONS.CMD.LONGPORTFIELD));
        }
        mongodb_port = (int) (cmd.hasOption(JobExecutorConfig.OPTIONS.CMD.LONGMONGOPORTFIELD)
                ? cmd.hasOption(JobExecutorConfig.OPTIONS.CMD.LONGMONGOPORTFIELD)
                : JobExecutorConfig.OPTIONS.LOGGING.MONGO_DEFAULT_PORT);
        mongodb_ip = InetAddress.getByName(cmd.getOptionValue(JobExecutorConfig.OPTIONS.CMD.LONGMONGOIPFIELD));

        vmscheduler_ip = InetAddress.getByName(cmd.getOptionValue(JobExecutorConfig.OPTIONS.CMD.LONGIPFIELD));

        decryptKey = cmd.getOptionValue("decrypt-key");

        debugState = cmd.hasOption(JobExecutorConfig.OPTIONS.CMD.LONGDEBUGFIELD);

        logger = LoggerFactory.getLogger();
        logger.info("Attempt to connect on master @" + vmscheduler_ip + ":" + vmscheduler_port);

        new RequestConsumer().start();

    } catch (MissingOptionException moe) {
        logger.error(moe.getMissingOptions() + " are missing");
        HelpFormatter help = new HelpFormatter();
        help.printHelp(JobExecutor.class.getSimpleName(), options);

    } catch (UnknownHostException ex) {
        logger.error(ex.getMessage());
    } finally {
        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                logger.info("JobExeutor is shutting down");
            }
        });
    }
}

From source file:com.runwaysdk.system.metadata.MetadataPatcher.java

@SuppressWarnings("static-access")
public static void main(String[] args) {
    Options options = new Options();
    options.addOption(OptionBuilder.withArgName("vendor").hasArg()
            .withDescription("Database vendor [" + POSTGRESQL + "]").isRequired().create("d"));
    options.addOption(OptionBuilder.withArgName("username").hasArg().withDescription("Database username")
            .isRequired().create("u"));
    options.addOption(OptionBuilder.withArgName("password").hasArg().withDescription("Database password")
            .isRequired().create("p"));
    options.addOption(/*from w w  w .  j  ava2 s.  c  om*/
            OptionBuilder.withArgName("url").hasArg().withDescription("Database URL").isRequired().create("l"));

    CommandLineParser parser = new BasicParser();

    try {
        CommandLine cmd = parser.parse(options, args);

        MetadataPatcher patcher = new MetadataPatcher();
        patcher.setDbms(cmd.getOptionValue("d"));
        patcher.setUserid(cmd.getOptionValue("u"));
        patcher.setPassword(cmd.getOptionValue("p"));
        patcher.setUrl(cmd.getOptionValue("l"));
        patcher.run();
    } catch (ParseException exp) {
        System.err.println("Parsing failed.  Reason: " + exp.getMessage());
    } catch (RuntimeException exp) {
        System.err.println("Patching failed. Reason: " + exp.getMessage());
    }
}