List of usage examples for java.lang System getProperties
public static Properties getProperties()
From source file:edu.hawaii.soest.hioos.storx.StorXEmailUtil.java
/** * @param args// ww w. j a v a 2 s . c o m */ public static void main(String[] args) { // get a connection to the mail server Properties props = System.getProperties(); props.setProperty("mail.store.protocol", protocol); props.setProperty("mail.imaps.partialfetch", prefetch); log.debug("\n\nACCOUNT DETAILS: \n" + "accountName : " + accountName + "\n" + "server : " + server + "\n" + "username : " + username + "\n" + "password : " + password + "\n" + "protocol : " + protocol + "\n" + "dataMailbox : " + sourceMailbox + "\n" + "prefetch : " + prefetch + "\n"); try { // create the imaps mail session mailSession = Session.getDefaultInstance(props, null); mailStore = mailSession.getStore(protocol); mailStore.connect(server, username, password); // get folder references for the inbox and processed data box //createFolders(targetMailbox); organizeMessages(sourceMailbox, targetMailbox); } catch (NoSuchProviderException nspe) { nspe.printStackTrace(); } catch (MessagingException e) { e.printStackTrace(); } finally { try { mailStore.close(); } catch (MessagingException e) { e.printStackTrace(); } } }
From source file:JAXPTransletMultipleTransformations.java
public static void main(String argv[]) { // Set the TransformerFactory system property to generate and use translets. // 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 w w w . j a v a 2 s .c om System.setProperties(props); String xslInURI = "todo.xsl"; try { // Instantiate the TransformerFactory, and use it along with a SteamSource // XSL stylesheet to create a translet as a Templates object. TransformerFactory tFactory = TransformerFactory.newInstance(); Templates translet = tFactory.newTemplates(new StreamSource(xslInURI)); // Perform each transformation doTransform(translet, "todo.xml", "todo.html"); System.out.println("Produced todo.html"); doTransform(translet, "todotoo.xml", "todotoo.html"); System.out.println("Produced todotoo.html"); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.barclays.dfe.fw.DFEWatcher.java
/** * Main entry point for application./*from w w w . j a v a 2 s .c o m*/ * * @param args the arguments * @throws DFEException the DFE exception */ public static void main(String[] args) throws DFEException { Properties properties = System.getProperties(); String usage; //Package pkg = org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.class.getPackage(); //Package pkg = DFEWatcher.class.getPackage().getImplementationTitle(); //String ver = pkg.getImplementationVersion(); String impVer = DFEWatcher.class.getPackage().getImplementationVersion(); String impTitle = DFEWatcher.class.getPackage().getImplementationTitle(); String impVendor = DFEWatcher.class.getPackage().getImplementationVendor(); String specVer = DFEWatcher.class.getPackage().getSpecificationVersion(); String specTitle = DFEWatcher.class.getPackage().getSpecificationTitle(); String specVendor = DFEWatcher.class.getPackage().getSpecificationVendor(); //String ver = pkg.getImplementationVersion(); usage = "\nProduct: " + impTitle + "\nVersion: " + impVer + "\nVendor:" + impVendor; System.out.println("Barclays DTU File Express (DFE) (C) 2014 - Designed and Written by Barclays GTIS"); System.out.println(usage); System.out.printf("DFE is using Java Runtime Version: %s VM: %s Runtime:%s\n\n", properties.getProperty("java.version"), properties.getProperty("java.vm.version"), properties.getProperty("java.runtime.version")); // Run the main class here - start logging here // Load the config file - mandatory - should also contain the name of the XML for the props DFEProps.getDFEProps(); Logger logger = LoggerFactory.getLogger(DFEWatcher.class); logger.debug("Thread mulitplier {}", DFEProps.DFEThreadMultipler); DFEShutdownGraceful gs = new DFEShutdownGraceful(); gs.attachShutDownHook(); // create the command line parser - this is the main entry point to detect how we want to invoke the client CommandLineParser parser = new PosixParser(); // create the Options Options options = new Options(); // boolean options options.addOption("h", "help", false, "General Help Page - this screen!"); options.addOption("wm", "WaitMode", false, "Run the DFE Client as a service and watched folder mode"); options.addOption("j", "TestJython", false, "Test a Jython Script"); options.addOption("sf", "SourceFile", false, "Test a Jython Script - Source File"); options.addOption("tf", "TargetFile", false, "Test a Jython Script - Target File"); options.addOption("lc", "LogConfig", false, "Print out the full log, system and DFE configuration for the client"); options.addOption("v", "version", false, "Build version of this client Major.Minor.Build"); options.addOption("jetty", "jetty", false, "Start the Jetty Server for testing"); if (args.length == 0) { printUsage("DFEclient" + " (Posix)", options, System.out); printHelp(options); System.exit(0); } try { int argsfound = 0; // parse the command line arguments line = parser.parse(options, args, true); // Pass down all the options if (line.hasOption("help") && args.length == 1) { printUsage("DFEclient" + " (Posix)", options, System.out); printHelp(options); System.exit(0); } if (line.hasOption("jetty")) { LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); StatusPrinter.print(lc); // Out put logging capability logger.info("System Config {} ", properties); //logger.info("DFE Client Config {} ",props.toString()); Server server = new Server(Integer.parseInt(DFEProps.getDFEAdminPort())); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/util"); server.setHandler(context); context.addServlet(new ServletHolder(new DFEServlet()), "/*"); context.addServlet(new ServletHolder(new DFEServlet("stop")), "/start/*"); context.addServlet(new ServletHolder(new DFEServlet("start")), "/stop/*"); context.addServlet(new ServletHolder(new DFEServlet("status")), "/status/*"); try { server.start(); server.join(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } logger.debug("Completed"); System.exit(0); } if (line.hasOption("lc")) { LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); StatusPrinter.print(lc); // Out put logging capability logger.info("System Config {} ", properties); DFEProps props = new DFEProps(); logger.info("DFE Client Config {} ", props.toString()); System.exit(0); } // Launch a Jython script to test the engine if (line.hasOption("j")) { DFETransferContext DFE = new DFETransferContext(); String sf = line.getOptionValue("sf"); String tf = line.getOptionValue("tf"); logger.info("System Config {} ", properties); DFEProps props = new DFEProps(); logger.info("DFE Client Config {} ", props.toString()); DFE.setDFESourceFile(sf); DFE.setDFETransferMode("put"); DFE.setDFETargetFileName(tf); String scriptName = line.getOptionValue("j"); argsfound++; logger.debug("Jython Script now executed {}", scriptName); DFEScriptEngine se = new DFEScriptEngine(); int result = se.RunPython(scriptName, DFE); logger.debug("Result from Jython Script {}", result); System.exit(0); } if (line.hasOption("v")) { logger.info(usage); System.exit(0); } // // Call this by default - this will be the main folder watcher // if (line.hasOption("wm")) { // Chek the status of the hub - and fail if we dont see it TODO - something better try { DFEUtils.DFECheckHub(); // Check the hub - if we get a fauilure - we } catch (Exception e) { System.exit(DFEProps.getDFEErrorReturnCode("DFE_HUB_ATTACH_ERROR")); } logger.info("All active propserties from DFE.properties"); DFEProps.printActiveProperties(); logger.info("End of Property List"); DFETransferContext dtx = new DFETransferContext(); DFEStatus stat = new DFEStatus(); logger.debug("Starting watched folder mode as a service"); argsfound++; try { // Shift the args to the left and remove -wm String[] newArgs; newArgs = new String[args.length - 1]; int i; for (i = 0; i < args.length - 1; i++) { newArgs[i] = args[i + 1]; } // Start the jetty server if admin port is non zero if (Integer.parseInt(DFEProps.DFEAdminPort) != 0) { // Start the Jetty server here logger.info("Starting Embedded JETTY server on {} /util ", DFEProps.DFEAdminPort); DFEJetty jettyServer = new DFEJetty(); EventQueue.invokeLater(jettyServer); } DFEScriptEngine se = new DFEScriptEngine(); logger.info("Starting startup.py script"); //String scriptName = DFEProps.DFEStartupScript; // Add the startup script location String scriptName = DFEProps.getDFEScriptsDir() + "//" + DFEProps.getDFEStartupScript(); //String scriptName = "startup.py"; dtx.setDFETransferMode("startup"); int result = se.RunPython(scriptName, dtx); //int result=0; if (result != 0) { logger.info("Startup script has terminated the application with error code {}", result); System.exit(0); } logger.info("Registering startup on log"); stat.registerStartup(true); // register the startup in log file logger.info("Starting watcher service"); DFEMasterRunState.startWatcher(); // Set the state flag try { JFileWatcherService.runWaitMode(newArgs); } catch (Exception e) { System.out.println("Exit from watcher"); logger.info("Graceful exit"); } logger.info("Terminating Watcher Service"); System.exit(0); } catch (Exception e) { // TODO Auto-generated catch block logger.error("Cannot start File Watcher Service: ", e); System.exit(-10); } logger.debug("Wait mode complete - exiting DFE Java Client"); } if (line.hasOption("im")) { logger.debug("Interactive mode complete - exiting DFE Java Client"); } if (argsfound == 0) { logger.error("Error: Unknown argument"); printUsage("DFEclient" + " (Posix)", options, System.out); printHelp(options); System.exit(0); System.exit(-8); } } // Catch the argument parser - here - only on a start catch (Exception exp) { logger.warn("Error in argument parsing {}", exp.toString()); System.exit(-9); } }
From source file:com.tacitknowledge.util.migration.jdbc.MigrationInformation.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 *//*from w w w . j a v a 2 s .c o m*/ public static void main(String[] arguments) throws Exception { MigrationInformation info = new MigrationInformation(); String migrationSystemName = ConfigurationUtil.getRequiredParam("migration.systemname", System.getProperties(), arguments, 0); String migrationSettings = ConfigurationUtil.getOptionalParam("migration.settings", System.getProperties(), arguments, 1); info.getMigrationInformation(migrationSystemName, 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.j a v a 2s.c o 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: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. c o 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:copier.java
public static void main(String argv[]) { boolean debug = false; // change to get more errors if (argv.length != 5) { System.out.println("usage: copier <urlname> <src folder>" + "<dest folder> <start msg #> <end msg #>"); return;// w w w . j a v a 2 s. c o m } try { URLName url = new URLName(argv[0]); String src = argv[1]; // source folder String dest = argv[2]; // dest folder int start = Integer.parseInt(argv[3]); // copy from message # int end = Integer.parseInt(argv[4]); // to message # // Get the default Session object Session session = Session.getInstance(System.getProperties(), null); // session.setDebug(debug); // Get a Store object that implements the protocol. Store store = session.getStore(url); store.connect(); System.out.println("Connected..."); // Open Source Folder Folder folder = store.getFolder(src); folder.open(Folder.READ_WRITE); System.out.println("Opened source..."); if (folder.getMessageCount() == 0) { System.out.println("Source folder has no messages .."); folder.close(false); store.close(); } // Open destination folder, create if needed Folder dfolder = store.getFolder(dest); if (!dfolder.exists()) // create dfolder.create(Folder.HOLDS_MESSAGES); Message[] msgs = folder.getMessages(start, end); System.out.println("Got messages..."); // Copy messages into destination, folder.copyMessages(msgs, dfolder); System.out.println("Copied messages..."); // Close the folder and store folder.close(false); store.close(); System.out.println("Closed folder and store..."); } catch (Exception e) { e.printStackTrace(); } System.exit(0); }
From source file:com.pinterest.terrapin.hadoop.HdfsUploader.java
public static void main(String[] args) { TerrapinUploaderOptions uploaderOptions = TerrapinUploaderOptions.initFromSystemProperties(); uploaderOptions.validate();//w ww.ja v a 2s . c o m String hdfsDir = System.getProperties().getProperty("terrapin.hdfs_dir"); Preconditions.checkNotNull(hdfsDir); try { new HdfsUploader(uploaderOptions, hdfsDir).upload(uploaderOptions.terrapinCluster, uploaderOptions.terrapinFileSet, uploaderOptions.loadOptions); } catch (Exception e) { LOG.error("Upload FAILED.", e); System.exit(1); } // We need to force an exit since some of the netty threads instantiated as part // of the process are not daemon threads. System.exit(0); }
From source file:transport.java
public static void main(String[] args) { Properties props = System.getProperties(); // parse the arguments InternetAddress[] addrs = null;/* ww w . ja va 2s. c o m*/ InternetAddress from; boolean debug = false; if (args.length != 4) { usage(); return; } else { props.put("mail.smtp.host", args[2]); if (args[3].equals("true")) { debug = true; } else if (args[3].equals("false")) { debug = false; } else { usage(); return; } // parse the destination addresses try { addrs = InternetAddress.parse(args[0], false); from = new InternetAddress(args[1]); } catch (AddressException aex) { System.out.println("Invalid Address"); aex.printStackTrace(); return; } } // create some properties and get a Session Session session = Session.getInstance(props, null); session.setDebug(debug); transport t = new transport(); t.go(session, addrs, from); }
From source file:sendfile.java
public static void main(String[] args) { if (args.length != 5) { System.out.println("usage: java sendfile <to> <from> <smtp> <file> true|false"); System.exit(1);//w w w. j a v a 2s .c o m } String to = args[0]; String from = args[1]; String host = args[2]; String filename = args[3]; boolean debug = Boolean.valueOf(args[4]).booleanValue(); String msgText1 = "Sending a file.\n"; String subject = "Sending a file"; // create some properties and get the default Session Properties props = System.getProperties(); props.put("mail.smtp.host", host); Session session = Session.getInstance(props, null); session.setDebug(debug); try { // create a message MimeMessage msg = new MimeMessage(session); msg.setFrom(new InternetAddress(from)); InternetAddress[] address = { new InternetAddress(to) }; msg.setRecipients(Message.RecipientType.TO, address); msg.setSubject(subject); // create and fill the first message part MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setText(msgText1); // create the second message part MimeBodyPart mbp2 = new MimeBodyPart(); // attach the file to the message mbp2.attachFile(filename); /* * Use the following approach instead of the above line if * you want to control the MIME type of the attached file. * Normally you should never need to do this. * FileDataSource fds = new FileDataSource(filename) { public String getContentType() { return "application/octet-stream"; } }; mbp2.setDataHandler(new DataHandler(fds)); mbp2.setFileName(fds.getName()); */ // create the Multipart and add its parts to it Multipart mp = new MimeMultipart(); mp.addBodyPart(mbp1); mp.addBodyPart(mbp2); // add the Multipart to the message msg.setContent(mp); // set the Date: header msg.setSentDate(new Date()); /* * If you want to control the Content-Transfer-Encoding * of the attached file, do the following. Normally you * should never need to do this. * msg.saveChanges(); mbp2.setHeader("Content-Transfer-Encoding", "base64"); */ // send the message Transport.send(msg); } catch (MessagingException mex) { mex.printStackTrace(); Exception ex = null; if ((ex = mex.getNextException()) != null) { ex.printStackTrace(); } } catch (IOException ioex) { ioex.printStackTrace(); } }