Example usage for java.lang System getenv

List of usage examples for java.lang System getenv

Introduction

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

Prototype

public static String getenv(String name) 

Source Link

Document

Gets the value of the specified environment variable.

Usage

From source file:net.siegmar.japtproxy.JaptProxyServer.java

/**
 * Starts the JaptProxyServer with the given parameters.
 *
 * @param args command line args./*  w  ww  . ja v a2  s .c  o m*/
 */
public static void main(final String[] args) {
    if (checkRequiredOptions()) {
        System.exit(1);
    }

    String configFile = System.getProperty(OPT_CONFIG);
    String contextPath = System.getProperty(OPT_CONTEXT_PATH);
    String logConfig = System.getProperty(OPT_LOG_CONFIG);
    final String host = System.getProperty(OPT_HOST);
    String port = System.getProperty(OPT_PORT);

    // Check settings
    if (configFile == null) {
        configFile = OPT_CONFIG_DEFAULT;
    }
    if (contextPath == null) {
        contextPath = OPT_CONTEXT_PATH_DEFAULT;
    }
    if (logConfig == null) {
        logConfig = OPT_LOG_CONFIG_DEFAULT;
    }
    if (port == null) {
        port = OPT_PORT_DEFAULT;
    }

    if (!new File(configFile).exists()) {
        System.err.println("Config file '" + configFile + "' doesn't exist");
        System.exit(1);
    }

    try {
        initializeLogging(logConfig);
    } catch (final RuntimeException e) {
        System.err.println("Couldn't initialize logging");
        e.printStackTrace(System.err);
        System.exit(1);
    }

    final Logger log = LoggerFactory.getLogger(JaptProxyServer.class);

    // Remove PID_FILE if specified
    final String pidFile = System.getenv("PID_FILE");
    if (pidFile != null) {
        log.debug("Will try to delete PID_FILE {} on exit", pidFile);
        new File(pidFile).deleteOnExit();
    }

    try {
        final int portNumber = Integer.parseInt(port);
        startServer(host, portNumber, StringUtils.stripEnd(contextPath, "/"));
    } catch (final NumberFormatException e) {
        log.error("The specified port number {} is not a number", port);
        System.exit(1);
    } catch (final RuntimeException e) {
        log.error("Error while starting server", e);
        System.exit(1);
    }
}

From source file:de.tudarmstadt.ukp.uby.integration.alignment.xml.transform.sensealignments.VnWnSenseAlignmentXml.java

public static void main(String[] args) {
    String UBY_HOME = System.getenv("UBY_HOME");
    String alfile = UBY_HOME + "/VerbNet/verbNetWordNetAlignment3.2.srt";
    String outFile = UBY_HOME + "/target/verbNetWordNetAlignment3.2_gen.xml";
    VnWnSenseAlignmentXml al = new VnWnSenseAlignmentXml(alfile, outFile);
    al.toAlignmentXml(al.getDefaultXmlMeta());
}

From source file:com.microsoft.azure.management.trafficmanager.samples.ManageSimpleTrafficManager.java

/**
 * Main entry point.// w w w.  j  a v  a  2  s.c o m
 * @param args the parameters
 */
public static void main(String[] args) {
    try {
        //=============================================================
        // Authenticate
        //
        System.out.println("AZURE_AUTH_LOCATION=" + System.getenv("AZURE_AUTH_LOCATION"));
        final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
        Azure azure = Azure.authenticate(credFile).withDefaultSubscription();

        // Print selected subscription
        System.out.println("Selected subscription: " + azure.subscriptionId());

        runSample(azure);
    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
    }
}

From source file:io.fluo.stress.trie.NumberIngest.java

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

    // Parse arguments
    if (args.length != 4) {
        log.error("Usage: NumberIngest <numMappers> <numbersPerMapper> <nodeSize> <fluoProps>");
        System.exit(-1);/*ww  w  .  j a v a 2s  .c  o  m*/
    }
    int numMappers = Integer.parseInt(args[0]);
    int numPerMapper = Integer.parseInt(args[1]);
    int nodeSize = Integer.parseInt(args[2]);
    String fluoPropsPath = args[3];

    String hadoopPrefix = System.getenv("HADOOP_PREFIX");
    if (hadoopPrefix == null) {
        hadoopPrefix = System.getenv("HADOOP_HOME");
        if (hadoopPrefix == null) {
            log.error("HADOOP_PREFIX or HADOOP_HOME needs to be set!");
            System.exit(-1);
        }
    }

    // create test name
    String testId = String.format("test-%d", (new Date().getTime() / 1000));
    String testDir = "/trie-stress/" + testId;

    setupHdfs(hadoopPrefix, testDir, numMappers, numPerMapper);

    JobConf ingestConf = new JobConf(NumberIngest.class);
    ingestConf.setJobName("NumberIngest");

    FluoConfiguration config = new FluoConfiguration(new File(fluoPropsPath));

    loadConfig(ingestConf, ConfigurationConverter.getProperties(config));
    ingestConf.setInt(TRIE_NODE_SIZE_PROP, nodeSize);

    ingestConf.setOutputKeyClass(LongWritable.class);
    ingestConf.setOutputValueClass(IntWritable.class);
    ingestConf.setMapperClass(NumberIngest.IngestMapper.class);
    ingestConf.setReducerClass(NumberIngest.UniqueReducer.class);

    FileInputFormat.setInputPaths(ingestConf, new Path(testDir + "/input/"));
    FileOutputFormat.setOutputPath(ingestConf, new Path(testDir + "/unique/"));

    RunningJob ingestJob = JobClient.runJob(ingestConf);
    ingestJob.waitForCompletion();
    if (ingestJob.isSuccessful()) {

        JobConf countConf = new JobConf(NumberIngest.class);
        countConf.setJobName("NumberCount");

        countConf.setOutputKeyClass(Text.class);
        countConf.setOutputValueClass(LongWritable.class);
        countConf.setMapperClass(NumberIngest.CountMapper.class);
        countConf.setReducerClass(NumberIngest.CountReducer.class);

        FileInputFormat.setInputPaths(countConf, new Path(testDir + "/unique/"));
        FileOutputFormat.setOutputPath(countConf, new Path(testDir + "/output/"));

        RunningJob countJob = JobClient.runJob(countConf);
        countJob.waitForCompletion();
        if (countJob.isSuccessful()) {
            log.info("Ingest and count jobs were successful");
            log.info("Output can be viewed @ " + testDir);
            System.exit(0);
        } else {
            log.error("Count job failed for " + testId);
        }
    } else {
        log.error("Ingest job failed.  Skipping count job for " + testId);
    }

    System.exit(-1);
}

From source file:com.microsoft.azure.management.appservice.samples.ManageWebAppStorageAccountConnection.java

/**
 * Main entry point./*  w  w w  .  j  ava  2  s . co m*/
 * @param args the parameters
 */
public static void main(String[] args) {

    try {

        //=============================================================
        // Authenticate

        final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));

        Azure azure = Azure.configure().withLogLevel(LogLevel.BASIC).authenticate(credFile)
                .withDefaultSubscription();

        // Print selected subscription
        System.out.println("Selected subscription: " + azure.subscriptionId());

        runSample(azure);
    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
    }
}

From source file:bogdanrechi.lansator.MainWindow.java

/**
 * Launch the application/*from  ww  w . ja va2  s  . c o m*/
 *
 * @param args
 *          Program arguments
 */
public static void main(String[] args) {
    Platform.validateCurrentJavaVersion("1.9");
    SwtPlatform.validateCurrentSwtVersion(4763);

    Run.DEBUG_ACTIVE = System.getenv("LANSATOR_DEBUG") != null;

    SingleInstance.ReceiveMessageDelegate receiveMessageDelegate = new SingleInstance.ReceiveMessageDelegate() {
        @Override
        public void receiveMessage(String message) {
            _mainWindow.showMainWindow();
        }
    };

    SingleInstance singleInstance = null;

    try {
        singleInstance = SingleInstance.request(SINGLE_INSTANCE_PORT, SINGLE_INSTANCE_HANDSHAKE,
                receiveMessageDelegate);
    } catch (StringException e2) {
        _mainWindow._log.fatal(ERROR_CANNOT_CREATE_SINGLE_INSTANCE_OBJECT);
        SwtMessageBox.messageBoxError(_mainWindow._localizedMessages.get("CRITICAL_APPLICATION_ERROR"));

        return;
    }

    if (singleInstance == null) {
        return;
    }

    _mainWindow = new MainWindow(Display.getDefault());

    _mainWindow._trayMain = new TrayItem(_mainWindow._display.getSystemTray(), SWT.NONE);

    try {
        _mainWindow._log = LogManager.getLogger(MainWindow.class);

        if (args.length == 1) {
            _mainWindow._language = args[0];
        }

        _mainWindow
                .setLocalizedMessages(new Localization(_mainWindow._language, LansatorResources.MESSAGES_JSON));
        _mainWindow
                .setLocalizedControls(new Localization(_mainWindow._language, LansatorResources.CONTROLS_JSON));

        _mainWindow.loadConfiguration();

        _mainWindow.setDefaultImage(_mainWindow._swtResourceManager.loadResourceImage(MainWindow.class,
                _mainWindow._defaultImagePath));

        _mainWindow.createContents();

        _mainWindow.setup();

        _mainWindow.setVisible(false);
        _mainWindow.setInitialSize();

        while (!_mainWindow.isDisposed()) {
            if (!_mainWindow._display.readAndDispatch()) {
                _mainWindow._display.sleep();
            }
        }
    } catch (Throwable e) {
        _mainWindow._log.fatal(Run.getExceptionStackTrace(e));
        _mainWindow.displayFatalErrorAndExit("CRITICAL_APPLICATION_ERROR");
    } finally {
        _mainWindow._trayMain.dispose();

        try {
            singleInstance.closeInstance();
        } catch (StringException e) {
            _mainWindow._log.fatal(Run.getExceptionStackTrace(e));
        }
    }
}

From source file:com.flyhz.avengers.framework.application.CrawlApplication.java

/**
 * @param args/*from  w  ww. java 2  s .  c  o  m*/
 *            Command line args
 */
public static void main(String[] args) {
    boolean result = false;
    LOG.info("classpath -> {}", System.getenv("CLASSPATH"));
    try {
        CrawlApplication crawlApplication = new CrawlApplication();
        LOG.info("Initializing CrawlvApplication");
        boolean doRun = crawlApplication.init(args);
        if (!doRun) {
            System.exit(0);
        }
        result = crawlApplication.run();
    } catch (Throwable t) {
        LOG.error("Error running CrawlApplication", t);
        System.exit(1);
    }
    if (result) {
        LOG.info("Application Crawl completed successfully. exiting");
        System.exit(0);
    } else {
        LOG.info("Application Crawl failed. exiting");
        System.exit(2);
    }
}

From source file:io.compgen.cgpipe.CGPipe.java

public static void main(String[] args) {
    String fname = null;//ww w. j  av  a2  s  .c o  m
    String logFilename = null;
    String outputFilename = null;
    PrintStream outputStream = null;

    int verbosity = 0;
    boolean silent = false;
    boolean dryrun = false;
    boolean silenceStdErr = false;
    boolean showHelp = false;

    List<String> targets = new ArrayList<String>();
    Map<String, VarValue> confVals = new HashMap<String, VarValue>();

    String k = null;

    for (int i = 0; i < args.length; i++) {
        String arg = args[i];
        if (i == 0) {
            if (new File(arg).exists()) {
                fname = arg;
                silenceStdErr = true;
                continue;
            }
        } else if (args[i - 1].equals("-f")) {
            fname = arg;
            continue;
        } else if (args[i - 1].equals("-l")) {
            logFilename = arg;
            continue;
        } else if (args[i - 1].equals("-o")) {
            outputFilename = arg;
            continue;
        }

        if (arg.equals("-h") || arg.equals("-help") || arg.equals("--help")) {
            if (k != null) {
                if (k.contains("-")) {
                    k = k.replaceAll("-", "_");
                }
                confVals.put(k, VarBool.TRUE);
            }
            showHelp = true;
        } else if (arg.equals("-license")) {
            license();
            System.exit(1);
        } else if (arg.equals("-s")) {
            if (k != null) {
                if (k.contains("-")) {
                    k = k.replaceAll("-", "_");
                }
                confVals.put(k, VarBool.TRUE);
            }
            silent = true;
        } else if (arg.equals("-nolog")) {
            if (k != null) {
                if (k.contains("-")) {
                    k = k.replaceAll("-", "_");
                }
                confVals.put(k, VarBool.TRUE);
            }
            silenceStdErr = true;
        } else if (arg.equals("-v")) {
            if (k != null) {
                if (k.contains("-")) {
                    k = k.replaceAll("-", "_");
                }
                confVals.put(k, VarBool.TRUE);
            }
            verbosity++;
        } else if (arg.equals("-vv")) {
            if (k != null) {
                if (k.contains("-")) {
                    k = k.replaceAll("-", "_");
                }
                confVals.put(k, VarBool.TRUE);
            }
            verbosity += 2;
        } else if (arg.equals("-vvv")) {
            if (k != null) {
                if (k.contains("-")) {
                    k = k.replaceAll("-", "_");
                }
                confVals.put(k, VarBool.TRUE);
            }
            verbosity += 3;
        } else if (arg.equals("-dr")) {
            if (k != null) {
                if (k.contains("-")) {
                    k = k.replaceAll("-", "_");
                }
                confVals.put(k, VarBool.TRUE);
            }
            dryrun = true;
        } else if (arg.startsWith("--")) {
            if (k != null) {
                if (k.contains("-")) {
                    k = k.replaceAll("-", "_");
                }
                confVals.put(k, VarBool.TRUE);
            }
            k = arg.substring(2);
        } else if (k != null) {
            if (k.contains("-")) {
                k = k.replaceAll("-", "_");
            }
            if (confVals.containsKey(k)) {
                try {
                    VarValue val = confVals.get(k);
                    if (val.getClass().equals(VarList.class)) {
                        ((VarList) val).add(VarValue.parseStringRaw(arg));
                    } else {
                        VarList list = new VarList();
                        list.add(val);
                        list.add(VarValue.parseStringRaw(arg));
                        confVals.put(k, list);
                    }
                } catch (VarTypeException e) {
                    System.err.println("Error setting variable: " + k + " => " + arg);
                    System.exit(1);
                    ;
                }
            } else {
                confVals.put(k, VarValue.parseStringRaw(arg));
            }
            k = null;
        } else if (arg.charAt(0) != '-') {
            targets.add(arg);
        }
    }
    if (k != null) {
        if (k.contains("-")) {
            k = k.replaceAll("-", "_");
        }
        confVals.put(k, VarBool.TRUE);
    }

    confVals.put("cgpipe.loglevel", new VarInt(verbosity));

    if (fname == null) {
        usage();
        System.exit(1);
    }

    if (!showHelp) {
        switch (verbosity) {
        case 0:
            SimpleFileLoggerImpl.setLevel(Level.INFO);
            break;
        case 1:
            SimpleFileLoggerImpl.setLevel(Level.DEBUG);
            break;
        case 2:
            SimpleFileLoggerImpl.setLevel(Level.TRACE);
            break;
        case 3:
        default:
            SimpleFileLoggerImpl.setLevel(Level.ALL);
            break;
        }
    } else {
        SimpleFileLoggerImpl.setLevel(Level.FATAL);
    }

    SimpleFileLoggerImpl.setSilent(silenceStdErr || showHelp);

    Log log = LogFactory.getLog(CGPipe.class);
    log.info("Starting new run: " + fname);

    if (logFilename != null) {
        confVals.put("cgpipe.log", new VarString(logFilename));
    }

    if (System.getenv("CGPIPE_DRYRUN") != null && !System.getenv("CGPIPE_DRYRUN").equals("")) {
        dryrun = true;
    }

    JobRunner runner = null;
    try {
        // Load config values from global config. 
        RootContext root = new RootContext();
        loadInitFiles(root);

        // Load settings from environment variables.
        root.loadEnvironment();

        // Set cmd-line arguments
        if (silent) {
            root.setOutputStream(null);
        }

        if (outputFilename != null) {
            outputStream = new PrintStream(new FileOutputStream(outputFilename));
            root.setOutputStream(outputStream);
        }

        for (String k1 : confVals.keySet()) {
            log.info("config: " + k1 + " => " + confVals.get(k1).toString());
        }

        root.update(confVals);
        root.set("cgpipe.procs", new VarInt(Runtime.getRuntime().availableProcessors()));

        // update the URL Source loader configs
        SourceLoader.updateRemoteHandlers(root.cloneString("cgpipe.remote"));

        // Now check for help, only after we've setup the remote handlers...
        if (showHelp) {
            try {
                Parser.showHelp(fname);
                System.exit(0);
            } catch (IOException e) {
                System.err.println("Unable to find pipeline: " + fname);
                System.exit(1);
            }
        }

        // Set the global config values
        //         globalConfig.putAll(root.cloneValues());

        // Parse the AST and run it
        Parser.exec(fname, root);

        // Load the job runner *after* we execute the script to capture any config changes
        runner = JobRunner.load(root, dryrun);

        // find a build-target, and submit the job(s) to a runner
        if (targets.size() > 0) {
            for (String target : targets) {
                log.debug("building: " + target);

                BuildTarget initTarget = root.build(target);
                if (initTarget != null) {
                    runner.submitAll(initTarget, root);
                } else {
                    System.out.println("CGPIPE ERROR: Unable to find target: " + target);
                }
            }
        } else {
            BuildTarget initTarget = root.build();
            if (initTarget != null) {
                runner.submitAll(initTarget, root);
                // Leave this commented out - it should be allowed to run cgpipe scripts w/o a target defined (testing)
                //            } else {
                //               System.out.println("CGPIPE ERROR: Unable to find default target");
            }
        }
        runner.done();

        if (outputStream != null) {
            outputStream.close();
        }

    } catch (ASTParseException | ASTExecException | RunnerException | FileNotFoundException e) {
        if (outputStream != null) {
            outputStream.close();
        }
        if (runner != null) {
            runner.abort();
        }

        if (e.getClass().equals(ExitException.class)) {
            System.exit(((ExitException) e).getReturnCode());
        }

        System.out.println("CGPIPE ERROR " + e.getMessage());
        if (verbosity > 0) {
            e.printStackTrace();
        }
        System.exit(1);
    }
}

From source file:de.tudarmstadt.ukp.uby.integration.alignment.xml.transform.sensealignments.FnWnSenseAlignmentXml.java

public static void main(String[] args) throws Exception {
    String UBY_HOME = System.getenv("UBY_HOME");
    String alignmentFile = UBY_HOME + "/alignments/WordFrameNet_formatted.tsv";
    String outFile = UBY_HOME + "/target/wordFrameNet_newXml.xml";
    DBConfig dbConfig = new DBConfig("localhost/uby_clarin_0_7_0", "com.mysql.jdbc.Driver", "mysql", "root",
            "pass", false);
    FnWnSenseAlignmentXml al = new FnWnSenseAlignmentXml(alignmentFile, outFile, dbConfig);
    al.toAlignmentXml(al.getDefaultXmlMeta());
}

From source file:alluxio.yarn.ApplicationMaster.java

/**
 * @param args Command line arguments to launch application master
 *//* w  w w  .  j av  a  2 s  .  co m*/
public static void main(String[] args) {
    Options options = new Options();
    options.addOption("num_workers", true, "Number of Alluxio workers to launch. Default 1");
    options.addOption("master_address", true, "(Required) Address to run Alluxio master");
    options.addOption("resource_path", true, "(Required) HDFS path containing the Application Master");

    try {
        LOG.info("Starting Application Master with args {}", Arrays.toString(args));
        final CommandLine cliParser = new GnuParser().parse(options, args);

        YarnConfiguration conf = new YarnConfiguration();
        UserGroupInformation.setConfiguration(conf);
        if (UserGroupInformation.isSecurityEnabled()) {
            String user = System.getenv("ALLUXIO_USER");
            UserGroupInformation ugi = UserGroupInformation.createRemoteUser(user);
            for (Token token : UserGroupInformation.getCurrentUser().getTokens()) {
                ugi.addToken(token);
            }
            LOG.info("UserGroupInformation: " + ugi);
            ugi.doAs(new PrivilegedExceptionAction<Void>() {
                @Override
                public Void run() throws Exception {
                    runApplicationMaster(cliParser);
                    return null;
                }
            });
        } else {
            runApplicationMaster(cliParser);
        }
    } catch (Exception e) {
        LOG.error("Error running Application Master", e);
        System.exit(1);
    }
}