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:web.ui.WebApplication.java

public static void main(String[] args) throws Exception {
    String webPort = System.getenv("PORT");
    if (webPort == null || webPort.isEmpty()) {
        webPort = "8080";
    }//  ww w. j  a  va  2s  .c  om
    System.setProperty("server.port", webPort);
    SpringApplication.run(WebApplication.class, args);
}

From source file:com.hotinno.feedmonitor.batch.Main.java

public static void main(String[] args) throws Throwable {
    try {//from   ww  w  .java 2 s  .  co  m
        log.error("Entering batch...");

        String env = System.getenv("VCAP_SERVICES");
        log.error("************************************************************************");
        log.error("VCAP_SERVICES is: " + env);
        log.error("************************************************************************");

        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(
                BuffaloBatchConfiguration.class);

        org.apache.commons.dbcp.BasicDataSource ds = (org.apache.commons.dbcp.BasicDataSource) applicationContext
                .getBean("myDataSource");

        log.error(String.format("URL: %s", ds.getUrl()));
        log.error(String.format("Username: %s", ds.getUsername()));
        log.error(String.format("Password: %s", ds.getPassword()));

        applicationContext.start();

        log.error("Running...");
    } catch (Throwable t) {
        System.err.println(t);
        t.printStackTrace();
        log.error("Error occurred.", t);
    }
}

From source file:com.example.main.Main.java

/**
 * @param args//from  w  ww.  ja v a2  s.co m
 */
public static void main(String[] args) throws Exception {
    String webappDirLocation = "src/main/webapp/";

    // The port that we should run on can be set into an environment variable
    // Look for that variable and default to 8080 if it isn't there.
    String webPort = System.getenv("PORT");
    if (webPort == null || webPort.isEmpty()) {
        webPort = "8082";
    }

    Server server = new Server(Integer.valueOf(webPort));
    WebAppContext root = new WebAppContext();

    root.setContextPath("/");
    root.setDescriptor(webappDirLocation + "/WEB-INF/web.xml");
    root.setResourceBase(webappDirLocation);

    PersistenceManager.getInstance().getEntityManagerFactory();

    // Parent loader priority is a class loader setting that Jetty accepts.
    // By default Jetty will behave like most web containers in that it will
    // allow your application to replace non-server libraries that are part of the
    // container. Setting parent loader priority to true changes this behavior.
    // Read more here: http://wiki.eclipse.org/Jetty/Reference/Jetty_Classloading
    root.setParentLoaderPriority(true);

    try {
        JSONObject datos = new JSONObject();
        datos.put("nombrePagina", "Competencias");
        datos.put("urlPagina", "localHost:8082");
        JSONObject datos2 = new JSONObject();
        datos2.put("nombrePagina", "Competencias");
        datos2.put("nuevoEstado", "Activo");
        JSONObject datos3 = new JSONObject();
        datos3.put("nombrePagina", "Competencias");
        datos3.put("nombreServicio", "Competencias");
        datos3.put("rutaServicio", "Competencias");
        JSONObject datos4 = new JSONObject();
        datos4.put("nombrePagina", "Competencias");
        datos4.put("nombreServicio", "Ganadores");
        datos4.put("rutaServicio", "Competencias/winners/{name}");

        Client client = Client.create();
        WebResource target = client.resource(SERVIDOR_ZK + "inscribirPagina");
        target.post(JSONObject.class, datos);
        target = client.resource(SERVIDOR_ZK + "estadoPagina");
        target.post(JSONObject.class, datos2);
        target = client.resource(SERVIDOR_ZK + "servicioPagina");
        target.post(JSONObject.class, datos3);
        target = client.resource(SERVIDOR_ZK + "servicioPagina");
        target.post(JSONObject.class, datos4);

        client.destroy();

    } catch (Exception e) {
        e.printStackTrace();
    }

    server.setHandler(root);

    server.start();
    server.join();
}

From source file:Env.java

public static void main(String[] args) {
    for (String env : args) {
        String value = System.getenv(env);
        if (value != null) {
            System.out.format("%s=%s%n", env, value);
        } else {//from ww w  .  ja v  a 2  s .  c  o m
            System.out.format("%s is not assigned.%n", env);
        }
    }
}

From source file:com.devbury.desktoplib.systemtray.SystemTrayApplication.java

public static void main(String[] args) {
    String appHome = System.getenv("APP_HOME");
    System.out.println("app home is " + appHome);
    if (appHome != null) {
        System.setProperty("app.home", appHome);
    }/*w w  w  . j  av a 2  s.  c  om*/
    SystemTrayApplication sta = newSystemTrayApplication();
    sta.setArgs(args);
    sta.configureLogging();
    sta.start();
}

From source file:alfio.config.SpringBootLauncher.java

/**
 * Entry point for spring boot/*ww  w. j av  a2s  .  c  om*/
 * @param args original arguments
 */
public static void main(String[] args) {
    Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler());
    String profiles = System.getProperty("spring.profiles.active", "");

    SpringApplication application = new SpringApplication(SpringBootInitializer.class,
            RepositoryConfiguration.class, DataSourceConfiguration.class, WebSecurityConfig.class,
            MvcConfiguration.class);
    List<String> additionalProfiles = new ArrayList<>();
    additionalProfiles.add(Initializer.PROFILE_SPRING_BOOT);
    if ("true".equals(System.getenv("ALFIO_LOG_STDOUT_ONLY"))) {
        // -> will load application-stdout.properties on top to override the logger configuration
        additionalProfiles.add("stdout");
    }
    if ("true".equals(System.getenv("ALFIO_DEMO_ENABLED"))) {
        additionalProfiles.add(Initializer.PROFILE_DEMO);
    }
    if ("true".equals(System.getenv("ALFIO_JDBC_SESSION_ENABLED"))) {
        additionalProfiles.add(Initializer.PROFILE_JDBC_SESSION);
    }
    application.setAdditionalProfiles(additionalProfiles.toArray(new String[additionalProfiles.size()]));
    ConfigurableApplicationContext applicationContext = application.run(args);
    ConfigurableEnvironment environment = applicationContext.getEnvironment();
    log.info("profiles: requested {}, active {}", profiles,
            String.join(", ", (CharSequence[]) environment.getActiveProfiles()));
    if ("true".equals(System.getProperty("startDBManager"))) {
        launchHsqlGUI();
    }
}

From source file:com.predic8.membrane.core.RouterCLI.java

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

    MembraneCommandLine cl = new MembraneCommandLine();
    cl.parse(args);//from   ww w .  j a v a  2s  .  c  o m
    if (cl.needHelp()) {
        cl.printUsage();
        return;
    }

    try {
        Router.init(getConfigFile(cl), RouterCLI.class.getClassLoader()).getConfigurationManager()
                .loadConfiguration(getRulesFile(cl));
        //System.out.println("preloading cache...");
        //ApplicationCachePreLoader.init();
    } catch (ClassNotFoundException e) {

        e.printStackTrace();

    } catch (PortOccupiedException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    } catch (Exception ex) {
        ex.printStackTrace();
        System.err.println(
                "Could not read rules configuration. Please specify a file containing rules using the -c command line option. Or make sure that the file "
                        + System.getenv("MEMBRANE_HOME") + "/conf/rules.xml exists");
        System.exit(1);
    }

    new RouterCLI().waitForever();

}

From source file:com.adito.upgrade.Upgrade.java

/**
 * @param args/*  w  ww. j ava 2s  .co m*/
 * @throws Exception on any error
 */
public static void main(String[] args) throws Exception {

    boolean gui = System.getProperty("os.name").toLowerCase().startsWith("windows")
            || System.getenv("DISPLAY") != null;

    if (args.length == 2 || !gui) {
        Upgrader upgrader = new CommandLineUpgrader(args);
        upgrader.upgrade();
    } else {
        JFrame f = new JFrame("0.1.16 to 0.2.5+ Upgrader");
        final Upgrader upgrader = new GUIUpgrader();
        f.setIconImage(new ImageIcon(Upgrade.class.getResource("upgrader-32x32.png")).getImage());
        f.getContentPane().setLayout(new BorderLayout());
        f.getContentPane().add((JPanel) upgrader, BorderLayout.CENTER);
        f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        JPanel bp = new JPanel(new FlowLayout(FlowLayout.RIGHT));
        final JButton start = new JButton("Start");
        ;
        final JButton close = new JButton("Close");
        start.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    start.setEnabled(false);
                    close.setEnabled(false);
                    upgrader.upgrade();
                } catch (Exception ex) {
                    upgrader.error("Failed to upgrade.", ex);
                } finally {
                    close.setEnabled(true);
                }
            }
        });
        close.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (close.isEnabled())
                    System.exit(0);
            }
        });
        bp.add(start);
        bp.add(close);
        f.getContentPane().add(bp, BorderLayout.SOUTH);
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent evt) {
                if (close.isEnabled())
                    System.exit(0);
            }
        });
        f.setSize(new Dimension(480, 460));
        UIUtil.positionComponent(SwingConstants.CENTER, f);
        f.setVisible(true);
    }
}

From source file:com.floragunn.searchguard.tools.Hasher.java

public static void main(final String[] args) {

    final Options options = new Options();
    final HelpFormatter formatter = new HelpFormatter();
    options.addOption(/*ww  w. j a va2  s .  c om*/
            Option.builder("p").argName("password").hasArg().desc("Cleartext password to hash").build());
    options.addOption(Option.builder("env").argName("name environment variable").hasArg()
            .desc("name environment variable to read password from").build());

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

        if (line.hasOption("p")) {
            System.out.println(hash(line.getOptionValue("p").getBytes("UTF-8")));
        } else if (line.hasOption("env")) {
            final String pwd = System.getenv(line.getOptionValue("env"));
            if (pwd == null || pwd.isEmpty()) {
                throw new Exception("No environment variable '" + line.getOptionValue("env") + "' set");
            }
            System.out.println(hash(pwd.getBytes("UTF-8")));
        } else {
            final Console console = System.console();
            if (console == null) {
                throw new Exception("Cannot allocate a console");
            }
            final char[] passwd = console.readPassword("[%s]", "Password:");
            System.out.println(hash(new String(passwd).getBytes("UTF-8")));
        }
    } catch (final Exception exp) {
        System.err.println("Parsing failed.  Reason: " + exp.getMessage());
        formatter.printHelp("hasher.sh", options, true);
        System.exit(-1);
    }
}

From source file:org.jrb.lots.SpringApplication.java

/**
 * Main entry point for the LOTS application.
 * /*from  w w  w . j a  v a  2s .  c o m*/
 * @param args
 *            the command line arguments
 */
public static void main(String[] args) {

    // determine application environment
    String appenv = System.getenv("APP_ENV");
    appenv = (appenv != null) ? appenv : ENV_LOCAL;

    // initialize application
    LOG.info("Starting application");
    new SpringApplicationBuilder(SpringApplication.class).profiles(appenv).showBanner(false).run(args);

}