Example usage for java.lang System getProperty

List of usage examples for java.lang System getProperty

Introduction

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

Prototype

public static String getProperty(String key) 

Source Link

Document

Gets the system property indicated by the specified key.

Usage

From source file:com.googlecode.jweb1t.FileMap.java

public static int main(final String args[]) throws IOException {
    String logConfig = System.getProperty("log-config");
    if (logConfig == null) {
        logConfig = "log-config.txt";
    }//from w ww .  j  ava2 s .  com

    if (args.length != 2) {
        System.out.println("java PACKAGE.FileMap index-file char"); // NOPMD
        return -1;
    }

    final String ch = args[1].substring(0, 1);

    final FileMap map = new FileMap(new File(args[0]));
    final String[] s = map.get(ch);

    System.out.print("\"" + ch + "\"\t"); // NOPMD

    for (int i = 0; i < s.length; i++) {
        if (i > 0) {
            System.out.print(" "); // NOPMD
        }
        System.out.print(s[i]); // NOPMD
    }

    System.out.print("\n"); // NOPMD
    return 0;
}

From source file:org.apache.samza.sql.master.SamzaSQLMaster.java

public static void main(String[] args) throws Exception {
    Server jettyServer = createJettyServer();

    try {// ww  w  . j av a 2  s  .  c o  m
        jettyServer.start();

        String mode = System.getProperty(PROP_MODE);
        if (mode != null && mode.trim().equals("dev")) {
            jettyServer.dump(System.err);
        }

        jettyServer.join();
    } finally {
        jettyServer.destroy();
    }
}

From source file:com.tacitknowledge.util.migration.jdbc.DistributedMigrationInformation.java

/**
 * Get the migration level information for the given system name
 *
 * @param arguments the command line arguments, if any (none are used)
 * @throws Exception if anything goes wrong
 *//* w  ww .j  a va 2 s.co  m*/
public static void main(String[] arguments) throws Exception {
    DistributedMigrationInformation info = new DistributedMigrationInformation();
    String migrationName = System.getProperty("migration.systemname");
    String migrationSettings = ConfigurationUtil.getOptionalParam("migration.settings", System.getProperties(),
            arguments, 1);

    if (migrationName == null) {
        if ((arguments != null) && (arguments.length > 0)) {
            migrationName = arguments[0].trim();
        } else {
            throw new IllegalArgumentException("The migration.systemname " + "system property is required");
        }
    }
    // info.getMigrationInformation(migrationName);
    info.getMigrationInformation(migrationName, migrationSettings);
}

From source file:info.usbo.skypetwitter.Run.java

public static void main(String[] args) {
    System.out.println("Working Directory = " + System.getProperty("user.dir"));
    Properties props;/*from w  ww . ja v  a 2 s  . co  m*/
    props = (Properties) System.getProperties().clone();
    //loadProperties(props, "D:\\Data\\Java\\classpath\\twitter.props");
    work_dir = System.getProperty("user.dir");
    loadProperties(props, work_dir + "\\twitter.props");
    twitter_user_id = props.getProperty("twitter.user");
    twitter_timeout = Integer.parseInt(props.getProperty("twitter.timeout"));
    System.out.println("Twitter user: " + twitter_user_id);
    System.out.println("Twitter timeout: " + twitter_timeout);
    if ("".equals(twitter_user_id)) {
        return;
    }
    if (load_file() == 0) {
        System.out.println("File not found");
        return;
    }
    while (true) {
        bChanged = 0;
        /*
        create_id();
        Chat ch = Chat.getInstance(chat_group_id);
        ch.send("!");
        */
        SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm");
        System.out.println("Looking at " + sdf.format(Calendar.getInstance().getTime()));
        Chat ch = Chat.getInstance(chat_group_id);
        Twitter twitter = new TwitterFactory().getInstance();
        try {
            List<Status> statuses;
            statuses = twitter.getUserTimeline(twitter_user_id);
            //System.out.println("Showing @" + twitter_user_id + "'s user timeline.");
            String sText;
            for (Status status : statuses) {
                //System.out.println(status.getId());
                Date d = status.getCreatedAt();
                //   ?
                Calendar cal = Calendar.getInstance();
                cal.setTime(d);
                cal.add(Calendar.HOUR_OF_DAY, 7);
                d = cal.getTime();
                sText = "@" + status.getUser().getScreenName() + "  " + sdf.format(d)
                        + " ( https://twitter.com/" + twitter_user_id + "/status/" + status.getId() + " ): \r\n"
                        + status.getText() + "\r\n***";
                for (URLEntity e : status.getURLEntities()) {
                    sText = sText.replaceAll(e.getURL(), e.getExpandedURL());
                }
                for (MediaEntity e : status.getMediaEntities()) {
                    sText = sText.replaceAll(e.getURL(), e.getMediaURL());
                }
                if (twitter_ids.indexOf(status.getId()) == -1) {
                    System.out.println(sText);
                    ch.send(sText);
                    twitter_ids.add(status.getId());
                    bChanged = 1;
                }
            }
        } catch (TwitterException te) {
            te.printStackTrace();
            System.out.println("Failed to get timeline: " + te.getMessage());
            //System.exit(-1);
        } catch (SkypeException ex) {
            ex.printStackTrace();
            System.out.println("Failed to send message: " + ex.getMessage());
        }

        // VK
        try {
            vk();
            for (VK v : vk) {
                if (vk_ids.indexOf(v.getId()) == -1) {
                    Date d = v.getDate();
                    //   ?
                    Calendar cal = Calendar.getInstance();
                    cal.setTime(d);
                    cal.add(Calendar.HOUR_OF_DAY, 7);
                    d = cal.getTime();
                    String sText = "@Depersonilized (VK)  " + sdf.format(d)
                            + " ( http://vk.com/Depersonilized?w=wall-0_" + v.getId() + " ): \r\n"
                            + v.getText();
                    if (!"".equals(v.getAttachment())) {
                        sText += "\r\n" + v.getAttachment();
                    }
                    sText += "\r\n***";
                    System.out.println(sText);
                    ch.send(sText);
                    vk_ids.add(v.getId());
                    bChanged = 1;
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
            System.out.println("Failed to get vk: " + e.getMessage());
            //System.exit(-1);
        } catch (SkypeException ex) {
            ex.printStackTrace();
            System.out.println("Failed to send message: " + ex.getMessage());
        }
        if (bChanged == 1) {
            save_file();
        }
        try {
            Thread.sleep(1000 * 60 * twitter_timeout);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
            System.out.println("Failed to sleep: " + ex.getMessage());
        }
    }
}

From source file:edu.uci.ics.asterix.transaction.management.service.locking.LockManagerDeterministicUnitTest.java

public static void main(String args[]) throws ACIDException, IOException, AsterixException {
    //prepare configuration file
    File cwd = new File(System.getProperty("user.dir"));
    File asterixdbDir = cwd.getParentFile();
    File srcFile = new File(asterixdbDir.getAbsoluteFile(),
            "asterix-app/src/main/resources/asterix-build-configuration.xml");
    File destFile = new File(cwd, "target/classes/asterix-configuration.xml");
    FileUtils.copyFile(srcFile, destFile);

    //initialize controller thread
    String requestFileName = new String(
            "src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/LockRequestFile");
    Thread t = new Thread(new LockRequestController(requestFileName));
    t.start();//from   ww w  . j  a v a 2  s. c  om
}

From source file:com.opensearchserver.affinities.Main.java

public static void main(String[] args) throws IOException, ParseException {
    Logger.getLogger("").setLevel(Level.WARNING);
    Options options = new Options();
    options.addOption("h", "help", false, "print this message");
    options.addOption("d", "datadir", true, "Data directory");
    options.addOption("p", "port", true, "TCP port");
    CommandLineParser parser = new GnuParser();
    CommandLine cmd = parser.parse(options, args);
    if (cmd.hasOption("help")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("java -jar target/oss-affinities.jar", options);
        return;/*from  w  w  w  .  ja v  a2 s .co m*/
    }
    int port = cmd.hasOption("p") ? Integer.parseInt(cmd.getOptionValue("p")) : 9092;

    File dataDir = new File(System.getProperty("user.home"), "opensearchserver_affinities");
    if (cmd.hasOption("d"))
        dataDir = new File(cmd.getOptionValue("d"));
    if (!dataDir.exists())
        throw new IOException("The data directory does not exists: " + dataDir);
    if (!dataDir.isDirectory())
        throw new IOException("The data directory path is not a directory: " + dataDir);
    AffinityList.load(dataDir);

    UndertowJaxrsServer server = new UndertowJaxrsServer()
            .start(Undertow.builder().addHttpListener(port, "0.0.0.0"));
    server.deploy(Main.class);
}

From source file:com.samczsun.helios.bootloader.Bootloader.java

public static void main(String[] args) {
    try {/*  ww  w  .  j a va 2s  . com*/
        if (!Constants.DATA_DIR.exists() && !Constants.DATA_DIR.mkdirs())
            throw new RuntimeException("Could not create data directory");
        if (!Constants.ADDONS_DIR.exists() && !Constants.ADDONS_DIR.mkdirs())
            throw new RuntimeException("Could not create addons directory");
        if (!Constants.SETTINGS_FILE.exists() && !Constants.SETTINGS_FILE.createNewFile())
            throw new RuntimeException("Could not create settings file");
        if (Constants.DATA_DIR.isFile())
            throw new RuntimeException("Data directory is file");
        if (Constants.ADDONS_DIR.isFile())
            throw new RuntimeException("Addons directory is file");
        if (Constants.SETTINGS_FILE.isDirectory())
            throw new RuntimeException("Settings file is directory");

        loadSWTLibrary();

        DisplayPumper displayPumper = new DisplayPumper();

        if (System.getProperty("os.name").toLowerCase().contains("mac")) {
            System.out.println("Attemting to force main thread");
            Executor executor;
            try {
                Class<?> dispatchClass = Class.forName("com.apple.concurrent.Dispatch");
                Object dispatchInstance = dispatchClass.getMethod("getInstance").invoke(null);
                executor = (Executor) dispatchClass.getMethod("getNonBlockingMainQueueExecutor")
                        .invoke(dispatchInstance);
            } catch (Throwable throwable) {
                throw new RuntimeException("Could not reflectively access Dispatch", throwable);
            }
            if (executor != null) {
                executor.execute(displayPumper);
            } else {
                throw new RuntimeException("Could not load executor");
            }
        } else {
            Thread pumpThread = new Thread(displayPumper);
            pumpThread.start();
        }
        while (!displayPumper.isReady())
            ;

        Display display = displayPumper.getDisplay();
        Shell shell = displayPumper.getShell();
        Splash splashScreen = new Splash(display);
        splashScreen.updateState(BootSequence.CHECKING_LIBRARIES);
        checkPackagedLibrary(splashScreen, "enjarify", Constants.ENJARIFY_VERSION,
                BootSequence.CHECKING_ENJARIFY, BootSequence.CLEANING_ENJARIFY, BootSequence.MOVING_ENJARIFY);
        checkPackagedLibrary(splashScreen, "Krakatau", Constants.KRAKATAU_VERSION,
                BootSequence.CHECKING_KRAKATAU, BootSequence.CLEANING_KRAKATAU, BootSequence.MOVING_KRAKATAU);
        Helios.main(args, shell, splashScreen);
        while (!displayPumper.isDone()) {
            Thread.sleep(100);
        }
    } catch (Throwable t) {
        displayError(t);
        System.exit(1);
    }
}

From source file:net.hydromatic.foodbench.Main.java

/** Main method. */
public static void main(String[] args) {
    try {/*from  www  .j  av  a2  s .  c om*/
        // E.g. Main -Dtest.ids=10,20-30,-23
        final RangeSet<Integer> idSet = parseInts(System.getProperty("foodbench.ids"));
        final boolean verbose = Boolean.parseBoolean(System.getProperty("foodbench.verbose"));

        Main main = new Main(idSet, verbose);

        switch (1) {
        case 0:
            main.run("jdbc:mysql://localhost?user=foodmart&password=foodmart", "foodmart",
                    "com.mysql.jdbc.Driver");
            break;
        case 1:
            main.run("jdbc:optiq:model=inline:" + OPTIQ_MODEL, "FOODMART_CLONE", null);
            break;
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }
}

From source file:net.recommenders.plista.client.Client.java

/**
 * This method starts the server/* ww  w  . ja  v  a  2 s.co m*/
 *
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {

    final Properties properties = new Properties();
    String fileName = "";
    String recommenderClass = null;
    String handlerClass = null;

    if (args.length < 3) {
        fileName = System.getProperty("propertyFile");
    } else {
        fileName = args[0];
        recommenderClass = args[1];
        handlerClass = args[2];
    }
    // load the team properties
    try {
        properties.load(new FileInputStream(fileName));
    } catch (IOException e) {
        logger.error(e.getMessage());
    } catch (Exception e) {
        logger.error(e.getMessage());
    }
    Recommender recommender = null;
    recommenderClass = (recommenderClass != null ? recommenderClass
            : properties.getProperty("plista.recommender"));
    System.out.println(recommenderClass);
    lognum = Integer.parseInt(properties.getProperty("plista.lognum"));
    try {
        final Class<?> transformClass = Class.forName(recommenderClass);
        recommender = (Recommender) transformClass.newInstance();
    } catch (Exception e) {
        logger.error(e.getMessage());
        throw new IllegalArgumentException("No recommender specified or recommender not available.");
    }
    // configure log4j
    /*if (args.length >= 4 && args[3] != null) {
    PropertyConfigurator.configure(args[0]);
         } else {
    PropertyConfigurator.configure("log4j.properties");
         }*/
    // set up and start server

    AbstractHandler handler = null;
    handlerClass = (handlerClass != null ? handlerClass : properties.getProperty("plista.handler"));
    System.out.println(handlerClass);
    try {
        final Class<?> transformClass = Class.forName(handlerClass);
        handler = (AbstractHandler) transformClass.getConstructor(Properties.class, Recommender.class)
                .newInstance(properties, recommender);
    } catch (Exception e) {
        logger.error(e.getMessage());
        e.printStackTrace();
        throw new IllegalArgumentException("No handler specified or handler not available.");
    }
    final Server server = new Server(Integer.parseInt(properties.getProperty("plista.port", "8080")));

    server.setHandler(handler);
    logger.debug("Serverport " + server.getConnectors()[0].getPort());

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

From source file:eu.mrbussy.pdfsplitter.Application.java

/**
 * Start the main program.//from   www .ja  v  a  2  s .co  m
 * 
 * @param args
 *            - Arguments passed on to the program
 */
public static void main(String[] args) {

    // Read configurations
    try {
        String configDirname = FilenameUtils.concat(System.getProperty("user.home"),
                String.format(".%1$s%2$s", NAME, IOUtils.DIR_SEPARATOR));
        String filename = FilenameUtils.concat(configDirname, CONFIGURATION_FILE);

        // Check to see if the directory exists and the file can be created/opened
        File configDir = new File(configDirname);
        if (!configDir.exists())
            configDir.mkdir();

        // Check to see if the file exists. If not create it
        File file = new File(filename);
        if (!file.exists()) {
            file.createNewFile();
        }
        Configuration = new PropertiesConfiguration(file);
        // Automatically store the settings that change
        Configuration.setAutoSave(true);

    } catch (ConfigurationException | IOException ex) {
        // Unable to read the file. Probably because it does not exist --> create it.
        ex.printStackTrace();
    }

    // Set locale to a configured language
    Locale.setDefault(
            new Locale(Configuration.getString("language", "nl"), Configuration.getString("country", "NL")));

    // Start by parsing the command line
    ParseCommandline(args);

    // Display the help if required and leave the app
    if (arguments.hasOption("h")) {
        showHelp();
    }

    // Display the app version and leave the app.
    if (arguments.hasOption("v")) {
        showVersion();
    }

    // Not command line so start the app GUI
    if (!arguments.hasOption("c")) {
        try {
            // Change the look and feel
            UIManager.setLookAndFeel(
                    Configuration.getString("LookAndFeel", "com.sun.java.swing.plaf.gtk.GTKLookAndFeel"));
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    (new MainWindow()).setVisible(true);
                }
            });
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
                | UnsupportedLookAndFeelException e) {
            // Something terrible happened so show the  help
            showHelp();
        }

    }

}