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:commonline.query.gui.Frame.java

public static void main(String args[]) throws Exception {
    Plastic3DLookAndFeel.setTabStyle(Plastic3DLookAndFeel.TAB_STYLE_METAL_VALUE);
    UIManager.setLookAndFeel("com.jgoodies.looks.plastic.Plastic3DLookAndFeel");

    System.setProperty("com.apple.macos.useScreenMenuBar", "true");

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("MainContext.xml");

    List dataSources = new ArrayList();
    dataSources.addAll(context.getBeansOfType(RecordParserDataSource.class).values());
    CommonlineRecordRepository repository = (CommonlineRecordRepository) context.getBean("clRepository");

    Frame frame = new Frame(System.getProperty("os.name").toLowerCase().indexOf("mac") != -1, dataSources,
            repository);//from  www  .  j a  va2  s  .c  om
    frame.setVisible(true);
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSwingHttpCLI.CFAsteriskSwingHttpCLI.java

public static void main(String args[]) {
    final String S_ProcName = "CFAsteriskSwingHttpCLI.main() ";
    initConsoleLog();//from  w  ww  . j a  va 2 s  . co m
    boolean fastExit = false;

    String homeDirName = System.getProperty("HOME");
    if (homeDirName == null) {
        homeDirName = System.getProperty("user.home");
        if (homeDirName == null) {
            log.message(S_ProcName + "ERROR: Home directory not set");
            return;
        }
    }
    File homeDir = new File(homeDirName);
    if (!homeDir.exists()) {
        log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" does not exist");
        return;
    }
    if (!homeDir.isDirectory()) {
        log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" is not a directory");
        return;
    }

    CFAsteriskClientConfigurationFile cFAsteriskClientConfig = new CFAsteriskClientConfigurationFile();
    String cFAsteriskClientConfigFileName = homeDir.getPath() + File.separator + ".cfasteriskclientrc";
    cFAsteriskClientConfig.setFileName(cFAsteriskClientConfigFileName);
    File cFAsteriskClientConfigFile = new File(cFAsteriskClientConfigFileName);
    if (!cFAsteriskClientConfigFile.exists()) {
        String cFAsteriskKeyStoreFileName = homeDir.getPath() + File.separator + ".msscfjceks";
        cFAsteriskClientConfig.setKeyStore(cFAsteriskKeyStoreFileName);
        InetAddress localHost;
        try {
            localHost = InetAddress.getLocalHost();
        } catch (UnknownHostException e) {
            localHost = null;
        }
        if (localHost == null) {
            log.message(S_ProcName + "ERROR: LocalHost is null");
            return;
        }
        String hostName = localHost.getHostName();
        if ((hostName == null) || (hostName.length() <= 0)) {
            log.message("ERROR: LocalHost.HostName is null or empty");
            return;
        }
        String userName = System.getProperty("user.name");
        if ((userName == null) || (userName.length() <= 0)) {
            log.message("ERROR: user.name is null or empty");
            return;
        }
        String deviceName = hostName.replaceAll("[^\\w]", "_").toLowerCase() + "-"
                + userName.replaceAll("[^\\w]", "_").toLowerCase();
        cFAsteriskClientConfig.setDeviceName(deviceName);
        cFAsteriskClientConfig.save();
        log.message(S_ProcName + "INFO: Created CFAsterisk client configuration file "
                + cFAsteriskClientConfigFileName);
        fastExit = true;
    }
    if (!cFAsteriskClientConfigFile.isFile()) {
        log.message(S_ProcName + "ERROR: Proposed client configuration file " + cFAsteriskClientConfigFileName
                + " is not a file.");
        fastExit = true;
    }
    if (!cFAsteriskClientConfigFile.canRead()) {
        log.message(S_ProcName + "ERROR: Permission denied attempting to read client configuration file "
                + cFAsteriskClientConfigFileName);
        fastExit = true;
    }
    cFAsteriskClientConfig.load();

    if (fastExit) {
        return;
    }

    // Configure logging
    Properties sysProps = System.getProperties();
    sysProps.setProperty("log4j.rootCategory", "WARN");
    sysProps.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger");

    Logger httpLogger = Logger.getLogger("org.apache.http");
    httpLogger.setLevel(Level.WARN);

    // The Invoker and it's implementation
    CFAsteriskXMsgClientHttpSchema invoker = new CFAsteriskXMsgClientHttpSchema();

    // And now for the client side cache implementation that invokes it
    ICFAsteriskSchemaObj clientSchemaObj = new CFAsteriskSchemaObj() {
        public void logout() {
            CFAsteriskXMsgClientHttpSchema invoker = (CFAsteriskXMsgClientHttpSchema) getBackingStore();
            try {
                invoker.logout(getAuthorization());
            } catch (RuntimeException e) {
            }
            setAuthorization(null);
        }
    };
    clientSchemaObj.setBackingStore(invoker);
    // And stitch the response handler to reference our client instance
    invoker.setResponseHandlerSchemaObj(clientSchemaObj);
    // And now we can stitch together the CLI to the SAX loader code
    CFAsteriskSwingHttpCLI cli = new CFAsteriskSwingHttpCLI();
    cli.setXMsgClientHttpSchema(invoker);
    cli.setSchema(clientSchemaObj);
    ICFAsteriskSwingSchema swing = cli.getSwingSchema();
    swing.setClientConfigurationFile(cFAsteriskClientConfig);
    swing.setSchema(clientSchemaObj);
    swing.setClusterName("system");
    swing.setTenantName("system");
    swing.setSecUserName("system");
    JFrame jframe = cli.getDesktop();
    jframe.setVisible(true);
    jframe.toFront();
}

From source file:com.chargebee.Application.MappingHeaders.java

public static void main(String[] args) throws Exception {
    String source1 = System.getProperty("user.home") + "/Output-3.csv"; // Source CSV file containing the customer details 
    String source2 = System.getProperty("user.home") + "/header.json";//Json file containing the customer id and token
    String output = System.getProperty("user.home") + "/Output-4.csv";// The destination CSV file.
    //        Scanner sc = new Scanner(System.in);
    //        System.out.println("Input CSV File: ");
    //        String source1 = sc.nextLine();
    ////  w w w . j av a2 s  . c om
    //        System.out.println("config File: ");
    //        String source2 = sc.nextLine();
    //
    //        System.out.println("Output CSV File: ");
    //        String output = sc.nextLine();
    //        

    MappingHeaders objHm = new MappingHeaders();
    JSONObject jobj = objHm.readJsonData(source2);
    CSVPrinter printer = new CSVPrinter(new FileWriter(output),
            CSVFormat.EXCEL.withRecordSeparator("\n").withDelimiter(','));
    CSVParser parser = new CSVParser(new FileReader(source1), CSVFormat.EXCEL.withHeader());
    objHm.extractJsonData(jobj, printer, parser);
    parser.close();
    printer.close();

}

From source file:com.ctriposs.rest4j.tools.snapshot.check.Rest4JSnapshotCompatibilityChecker.java

public static void main(String[] args) {
    final Options options = new Options();
    options.addOption("h", "help", false, "Print help");
    options.addOption(OptionBuilder.withArgName("compatibility_level").withLongOpt("compat").hasArg()
            .withDescription("Compatibility level " + listCompatLevelOptions()).create('c'));
    final String cmdLineSyntax = Rest4JSnapshotCompatibilityChecker.class.getCanonicalName()
            + " [pairs of <prevRestspecPath currRestspecPath>]";

    final CommandLineParser parser = new PosixParser();
    final CommandLine cmd;

    try {/* w ww  .  jav a2s .  c  o  m*/
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        new HelpFormatter().printHelp(cmdLineSyntax, options, true);
        System.exit(1);
        return; // to suppress IDE warning
    }

    final String[] targets = cmd.getArgs();
    if (cmd.hasOption('h') || targets.length < 2 || targets.length % 2 != 0) {
        new HelpFormatter().printHelp(cmdLineSyntax, options, true);
        System.exit(1);
    }

    final String compatValue;
    if (cmd.hasOption('c')) {
        compatValue = cmd.getOptionValue('c');
    } else {
        compatValue = CompatibilityLevel.DEFAULT.name();
    }

    final CompatibilityLevel compat;
    try {
        compat = CompatibilityLevel.valueOf(compatValue.toUpperCase());
    } catch (IllegalArgumentException e) {
        new HelpFormatter().printHelp(cmdLineSyntax, options, true);
        System.exit(1);
        return;
    }

    final StringBuilder allSummaries = new StringBuilder();
    boolean result = true;
    final String resolverPath = System.getProperty(AbstractGenerator.GENERATOR_RESOLVER_PATH);
    final Rest4JSnapshotCompatibilityChecker checker = new Rest4JSnapshotCompatibilityChecker();
    checker.setResolverPath(resolverPath);

    for (int i = 1; i < targets.length; i += 2) {
        String prevTarget = targets[i - 1];
        String currTarget = targets[i];
        CompatibilityInfoMap infoMap = checker.check(prevTarget, currTarget, compat);
        result &= infoMap.isCompatible(compat);
        allSummaries.append(infoMap.createSummary(prevTarget, currTarget));

    }

    if (compat != CompatibilityLevel.OFF && allSummaries.length() > 0) {
        System.out.println(allSummaries);
    }

    System.exit(result ? 0 : 1);
}

From source file:Manifest.java

public static void main(String[] args) throws Exception {
    // Set the default values of the command-line arguments
    boolean verify = false; // Verify manifest or create one?
    String manifestfile = "MANIFEST"; // Manifest file name
    String digestAlgorithm = "MD5"; // Algorithm for message digests
    String signername = null; // Signer. No sig. by default
    String signatureAlgorithm = "DSA"; // Algorithm for digital sig.
    String password = null; // Private keys are protected
    File keystoreFile = null; // Where are keys stored
    String keystoreType = null; // What kind of keystore
    String keystorePassword = null; // How to access keystore
    List filelist = new ArrayList(); // The files to digest

    // Parse the command-line arguments, overriding the defaults above
    for (int i = 0; i < args.length; i++) {
        if (args[i].equals("-v"))
            verify = true;//from w w  w .  j av  a 2 s.c  o m
        else if (args[i].equals("-m"))
            manifestfile = args[++i];
        else if (args[i].equals("-da") && !verify)
            digestAlgorithm = args[++i];
        else if (args[i].equals("-s") && !verify)
            signername = args[++i];
        else if (args[i].equals("-sa") && !verify)
            signatureAlgorithm = args[++i];
        else if (args[i].equals("-p"))
            password = args[++i];
        else if (args[i].equals("-keystore"))
            keystoreFile = new File(args[++i]);
        else if (args[i].equals("-keystoreType"))
            keystoreType = args[++i];
        else if (args[i].equals("-keystorePassword"))
            keystorePassword = args[++i];

        else if (!verify)
            filelist.add(args[i]);
        else
            throw new IllegalArgumentException(args[i]);
    }

    // If certain arguments weren't supplied, get default values.
    if (keystoreFile == null) {
        File dir = new File(System.getProperty("user.home"));
        keystoreFile = new File(dir, ".keystore");
    }
    if (keystoreType == null)
        keystoreType = KeyStore.getDefaultType();
    if (keystorePassword == null)
        keystorePassword = password;

    if (!verify && signername != null && password == null) {
        System.out.println("Use -p to specify a password.");
        return;
    }

    // Get the keystore we'll use for signing or verifying signatures
    // If no password was provided, then assume we won't be dealing with
    // signatures, and skip the keystore.
    KeyStore keystore = null;
    if (keystorePassword != null) {
        keystore = KeyStore.getInstance(keystoreType);
        InputStream in = new BufferedInputStream(new FileInputStream(keystoreFile));
        keystore.load(in, keystorePassword.toCharArray());
    }

    // If -v was specified or no file were given, verify a manifest
    // Otherwise, create a new manifest for the specified files
    if (verify || (filelist.size() == 0))
        verify(manifestfile, keystore);
    else
        create(manifestfile, digestAlgorithm, signername, signatureAlgorithm, keystore, password, filelist);
}

From source file:ExampleP2PHttpClient.java

public static void main(String[] args) {
    // initialize JXTA
    try {//  www.  j av a  2s  .c  o  m
        // sign in and initialize the JXTA network; profile this peer and create it
        // if it doesn't exist
        P2PNetwork.signin("clientpeer", "clientpeerpassword", "TestNetwork", true);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }

    // register the P2P socket protocol factory
    Protocol jxtaHttp = new Protocol("p2phttp", new P2PProtocolSocketFactory(), 80);
    Protocol.registerProtocol("p2phttp", jxtaHttp);

    //create a singular HttpClient object
    HttpClient client = new HttpClient();

    //establish a connection within 50 seconds
    client.setConnectionTimeout(50000);

    String url = System.getProperty("url");
    if (url == null || url.equals("")) {
        System.out.println("You must provide a URL to access.  For example:");
        System.out.println("ant example-webclient-run -D--url=p2phttp://www.somedomain.foo");

        System.exit(1);
    }
    System.out.println("Connecting to " + url + "...");

    HttpMethod method = null;

    //create a method object
    method = new GetMethod(url);
    method.setFollowRedirects(true);
    method.setStrictMode(false);
    //} catch (MalformedURLException murle) {
    //    System.out.println("<url> argument '" + url
    //            + "' is not a valid URL");
    //    System.exit(-2);
    //}

    //execute the method
    String responseBody = null;
    try {
        client.executeMethod(method);
        responseBody = method.getResponseBodyAsString();
    } catch (HttpException he) {
        System.err.println("Http error connecting to '" + url + "'");
        System.err.println(he.getMessage());
        System.exit(-4);
    } catch (IOException ioe) {
        System.err.println("Unable to connect to '" + url + "'");
        System.exit(-3);
    }

    //write out the request headers
    System.out.println("*** Request ***");
    System.out.println("Request Path: " + method.getPath());
    System.out.println("Request Query: " + method.getQueryString());
    Header[] requestHeaders = method.getRequestHeaders();
    for (int i = 0; i < requestHeaders.length; i++) {
        System.out.print(requestHeaders[i]);
    }

    //write out the response headers
    System.out.println("*** Response ***");
    System.out.println("Status Line: " + method.getStatusLine());
    Header[] responseHeaders = method.getResponseHeaders();
    for (int i = 0; i < responseHeaders.length; i++) {
        System.out.print(responseHeaders[i]);
    }

    //write out the response body
    System.out.println("*** Response Body ***");
    System.out.println(responseBody);

    //clean up the connection resources
    method.releaseConnection();
    method.recycle();

    System.exit(0);
}

From source file:dk.statsbiblioteket.util.qa.PackageScannerDriver.java

/**
 * @param args The command line arguments.
 * @throws IOException If command line arguments can't be passed or there
 *                     is an error reading class files.
 *///from w  ww.j a  v  a  2s .  c  o m
@SuppressWarnings("deprecation")
public static void main(final String[] args) throws IOException {
    Report report;
    CommandLine cli = null;
    String reportType, projectName, baseSrcDir, targetPackage;
    String[] targets = null;

    // Build command line options
    CommandLineParser cliParser = new PosixParser();
    Options options = new Options();
    options.addOption("h", "help", false, "Print help message and exit");
    options.addOption("n", "name", true, "Project name, default 'Unknown'");
    options.addOption("o", "output", true, "Type of output, 'plain' or 'html', default is html");
    options.addOption("p", "package", true, "Only scan a particular package in input dirs, use dotted "
            + "package notation to refine selections");
    options.addOption("s", "source-dir", true,
            "Base source dir to use in report, can be a URL. " + "@FILE@ and @MODULE@ will be escaped");

    // Parse and validate command line
    try {
        cli = cliParser.parse(options, args);
        targets = cli.getArgs();
        if (args.length == 0 || targets.length == 0 || cli.hasOption("help")) {
            throw new ParseException("Not enough arguments, no input files");
        }
    } catch (ParseException e) {
        printHelp(options);
        System.exit(1);
    }

    // Extract information from command line
    reportType = cli.getOptionValue("output") != null ? cli.getOptionValue("output") : "html";

    projectName = cli.getOptionValue("name") != null ? cli.getOptionValue("name") : "Unknown";

    baseSrcDir = cli.getOptionValue("source-dir") != null ? cli.getOptionValue("source-dir")
            : System.getProperty("user.dir");

    targetPackage = cli.getOptionValue("package") != null ? cli.getOptionValue("package") : "";
    targetPackage = targetPackage.replace(".", File.separator);

    // Set up report type
    if ("plain".equals(reportType)) {
        report = new BasicReport();
    } else {
        report = new HTMLReport(projectName, System.out, baseSrcDir);
    }

    // Do actual scanning of provided targets
    for (String target : targets) {
        PackageScanner scanner;
        File f = new File(target);

        if (f.isDirectory()) {
            scanner = new PackageScanner(report, f, targetPackage);
        } else {
            String filename = f.toString();
            scanner = new PackageScanner(report, f.getParentFile(),
                    filename.substring(filename.lastIndexOf(File.separator) + 1));
        }
        scanner.scan();
    }

    // Cloce the report before we exit
    report.end();
}

From source file:com.linkedin.restli.tools.snapshot.check.RestLiSnapshotCompatibilityChecker.java

public static void main(String[] args) {
    final Options options = new Options();
    options.addOption("h", "help", false, "Print help");
    options.addOption(OptionBuilder.withArgName("compatibility_level").withLongOpt("compat").hasArg()
            .withDescription("Compatibility level " + listCompatLevelOptions()).create('c'));
    options.addOption(OptionBuilder.withLongOpt("report").withDescription(
            "Prints a report at the end of the execution that can be parsed for reporting to other tools")
            .create("report"));
    final String cmdLineSyntax = RestLiSnapshotCompatibilityChecker.class.getCanonicalName()
            + " [pairs of <prevRestspecPath currRestspecPath>]";

    final CommandLineParser parser = new PosixParser();
    final CommandLine cmd;

    try {/*from ww  w  .  j  a  v  a2 s .  c  o m*/
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        new HelpFormatter().printHelp(cmdLineSyntax, options, true);
        System.exit(255);
        return; // to suppress IDE warning
    }

    final String[] targets = cmd.getArgs();
    if (cmd.hasOption('h') || targets.length < 2 || targets.length % 2 != 0) {
        new HelpFormatter().printHelp(cmdLineSyntax, options, true);
        System.exit(255);
    }

    final String compatValue;
    if (cmd.hasOption('c')) {
        compatValue = cmd.getOptionValue('c');
    } else {
        compatValue = CompatibilityLevel.DEFAULT.name();
    }

    final CompatibilityLevel compat;
    try {
        compat = CompatibilityLevel.valueOf(compatValue.toUpperCase());
    } catch (IllegalArgumentException e) {
        new HelpFormatter().printHelp(cmdLineSyntax, options, true);
        System.exit(255);
        return;
    }

    final String resolverPath = System.getProperty(AbstractGenerator.GENERATOR_RESOLVER_PATH);
    final RestLiSnapshotCompatibilityChecker checker = new RestLiSnapshotCompatibilityChecker();
    checker.setResolverPath(resolverPath);

    for (int i = 1; i < targets.length; i += 2) {
        String prevTarget = targets[i - 1];
        String currTarget = targets[i];
        checker.checkCompatibility(prevTarget, currTarget, compat, prevTarget.endsWith(".restspec.json"));
    }

    String summary = checker.getInfoMap().createSummary();

    if (compat != CompatibilityLevel.OFF && summary.length() > 0) {
        System.out.println(summary);
    }

    if (cmd.hasOption("report")) {
        System.out.println(new CompatibilityReport(checker.getInfoMap(), compat).createReport());
        System.exit(0);
    }

    System.exit(checker.getInfoMap().isCompatible(compat) ? 0 : 1);
}

From source file:com.rvantwisk.cnctools.Main.java

public static void main(String[] args) {

    // Detect OS/X and set AWT to that we can use OPenGL, this might not be needed fro Java 8
    final String osName = System.getProperty("os.name");
    final String javaVersion = System.getProperty("java.version");
    if (osName.contains("OS X")) {
        if (javaVersion.startsWith("1.7")) {
            System.setProperty("javafx.macosx.embedded", "true");
        }/*from   w  w w .jav  a2 s.  co  m*/
        java.awt.Toolkit.getDefaultToolkit();
    }

    launch(args);
}

From source file:com.nohowdezign.gcpmanager.Main.java

public final static void main(String[] args) {
    //Remove old log, it does not need to be there anymore.
    File oldLog = new File("./CloudPrintManager.log");

    if (oldLog.exists()) {
        oldLog.delete();//www  .ja  v  a 2s.  c  o m
    }

    //Create a file reader for the props file
    Reader propsStream = null;
    try {
        propsStream = new FileReader("./props.json");
    } catch (FileNotFoundException e1) {
        e1.printStackTrace();
    }

    PrintManagerProperties props = null;
    if (propsStream != null) {
        props = gson.fromJson(propsStream, PrintManagerProperties.class);
    } else {
        logger.error("Property file does not exist. Please create one.");
    }

    //Set the variables to what is in the props file
    String email = props.getEmail();
    String password = props.getPassword();
    String printerId = props.getPrinterId();
    amountOfPagesPerPrintJob = props.getAmountOfPagesPerPrintJob();
    timeRestraintsForPrinter = props.getTimeRestraintsForPrinter();

    JobStorageManager.timeToKeepFileInDays = props.getTimeToKeepFileInDays();

    //AuthenticationManager authenticationManager = new AuthenticationManager();
    //authenticationManager.setPasswordToUse(props.getAdministrativePassword());
    //authenticationManager.initialize(1337); //Start the authentication manager on port 1337

    try {
        cloudPrint.connect(email, password, "cloudprintmanager-1.0");
    } catch (CloudPrintAuthenticationException e) {
        logger.error(e.getMessage());
    }

    //TODO: Get a working website ready
    //Thread adminConsole = new Thread(new HttpServer(80), "HttpServer");
    //adminConsole.start();

    Thread printJobManager = new Thread(new JobStorageManagerThread(), "JobStorageManager");
    printJobManager.start();

    try {
        if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
            logger.error("Your operating system is not supported. Please switch to linux ya noob.");
            System.exit(1);
        } else {
            PrinterManager printerManager = new PrinterManager(cloudPrint);

            File cupsPrinterDir = new File("/etc/cups/ppd");

            if (cupsPrinterDir.isDirectory() && cupsPrinterDir.canRead()) {
                for (File cupsPrinterPPD : cupsPrinterDir.listFiles()) {
                    //Init all of the CUPS printers in the manager
                    printerManager.initializePrinter(cupsPrinterPPD, cupsPrinterPPD.getName());
                }
            } else {
                logger.error("Please run this with a higher access level.");
                System.exit(1);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    while (true) {
        try {
            getPrintingJobs(printerId);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}