Example usage for java.lang System setProperty

List of usage examples for java.lang System setProperty

Introduction

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

Prototype

public static String setProperty(String key, String value) 

Source Link

Document

Sets the system property indicated by the specified key.

Usage

From source file:core.PlanC.java

/**
 * inicio de aplicacion/*from  w  w  w.j  a  va2s.  com*/
 * 
 * @param arg - argumentos de entrada
 */
public static void main(String[] args) {

    // user.name

    /*
     * Properties prp = System.getProperties(); System.out.println(getWmicValue("bios", "SerialNumber"));
     * System.out.println(getWmicValue("cpu", "SystemName"));
     */

    try {
        // log
        // -Djava.util.logging.SimpleFormatter.format='%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s %2$s %5$s%6$s%n'
        // System.setProperty("java.util.logging.SimpleFormatter.format",
        // "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s %2$s %5$s%6$s%n");
        System.setProperty("java.util.logging.SimpleFormatter.format",
                "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %5$s%6$s%n");

        FileHandler fh = new FileHandler(LOG_FILE);
        fh.setFormatter(new SimpleFormatter());
        fh.setLevel(Level.INFO);
        ConsoleHandler ch = new ConsoleHandler();
        ch.setFormatter(new SimpleFormatter());
        ch.setLevel(Level.INFO);
        logger = Logger.getLogger("");
        Handler[] hs = logger.getHandlers();
        for (int x = 0; x < hs.length; x++) {
            logger.removeHandler(hs[x]);
        }
        logger.addHandler(fh);
        logger.addHandler(ch);
        // point apache log to this log
        System.setProperty("org.apache.commons.logging.Log", Jdk14Logger.class.getName());

        TPreferences.init();
        TStringUtils.init();

        Font fo = Font.createFont(Font.TRUETYPE_FONT, TResourceUtils.getFile("Dosis-Light.ttf"));
        GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(fo);
        fo = Font.createFont(Font.TRUETYPE_FONT, TResourceUtils.getFile("Dosis-Medium.ttf"));
        GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(fo);
        fo = Font.createFont(Font.TRUETYPE_FONT, TResourceUtils.getFile("AERO_ITALIC.ttf"));
        GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(fo);

        SwingTimerTimingSource ts = new SwingTimerTimingSource();
        AnimatorBuilder.setDefaultTimingSource(ts);
        ts.init();

        // parse app argument parameters and append to tpreferences to futher uses
        for (String arg : args) {
            String[] kv = arg.split("=");
            TPreferences.setProperty(kv[0], kv[1]);
        }
        RUNNING_MODE = TPreferences.getProperty("runningMode", RM_NORMAL);

        newMsg = Applet.newAudioClip(TResourceUtils.getURL("newMsg.wav"));

    } catch (Exception e) {
        SystemLog.logException1(e, true);
    }

    // pass icon from metal to web look and feel
    Icon i1 = UIManager.getIcon("OptionPane.errorIcon");
    Icon i2 = UIManager.getIcon("OptionPane.informationIcon");
    Icon i3 = UIManager.getIcon("OptionPane.questionIcon");
    Icon i4 = UIManager.getIcon("OptionPane.warningIcon");
    // Object fcui = UIManager.get("FileChooserUI");
    // JFileChooser fc = new JFileChooser();

    WebLookAndFeel.install();
    // WebLookAndFeel.setDecorateFrames(true);
    // WebLookAndFeel.setDecorateDialogs(true);

    UIManager.put("OptionPane.errorIcon", i1);
    UIManager.put("OptionPane.informationIcon", i2);
    UIManager.put("OptionPane.questionIcon", i3);
    UIManager.put("OptionPane.warningIcon", i4);
    // UIManager.put("TFileChooserUI", fcui);

    // warm up the IDW.
    // in my computer, some weird error ocurr if i don't execute this preload.
    new RootWindow(null);

    frame = new TWebFrame();
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            Exit.shutdown();
        }
    });

    if (RUNNING_MODE.equals(RM_NORMAL)) {
        initEnviorement();
    }
    if (RUNNING_MODE.equals(RM_CONSOLE)) {
        initConsoleEnviorement();
    }

    if (RUNNING_MODE.equals(ONE_TASK)) {
        String cln = TPreferences.getProperty("taskName", "*TaskNotFound");
        PlanC.logger.log(Level.INFO, "OneTask parameter found in .properties. file Task name = " + cln);
        try {
            Class cls = Class.forName(cln);
            Object dobj = cls.newInstance();
            // new class must be extends form AbstractExternalTask
            TTaskManager.executeTask((Runnable) dobj);
            return;
        } catch (Exception e) {
            PlanC.logger.log(Level.SEVERE, e.getMessage(), e);
            Exit.shutdown();
        }
    }
}

From source file:azkaban.jobtype.HadoopSecureHiveWrapper.java

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

    String propsFile = System.getenv(ProcessJob.JOB_PROP_ENV);
    Properties prop = new Properties();
    prop.load(new BufferedReader(new FileReader(propsFile)));

    hiveScript = prop.getProperty("hive.script");

    final Configuration conf = new Configuration();

    UserGroupInformation.setConfiguration(conf);
    securityEnabled = UserGroupInformation.isSecurityEnabled();

    if (shouldProxy(prop)) {
        UserGroupInformation proxyUser = null;
        String userToProxy = prop.getProperty("user.to.proxy");
        if (securityEnabled) {
            String filelocation = System.getenv(UserGroupInformation.HADOOP_TOKEN_FILE_LOCATION);
            if (filelocation == null) {
                throw new RuntimeException("hadoop token information not set.");
            }//from ww  w.j a v a 2s.com
            if (!new File(filelocation).exists()) {
                throw new RuntimeException("hadoop token file doesn't exist.");
            }

            logger.info("Found token file " + filelocation);

            logger.info("Setting " + HadoopSecurityManager.MAPREDUCE_JOB_CREDENTIALS_BINARY + " to "
                    + filelocation);
            System.setProperty(HadoopSecurityManager.MAPREDUCE_JOB_CREDENTIALS_BINARY, filelocation);

            UserGroupInformation loginUser = null;

            loginUser = UserGroupInformation.getLoginUser();
            logger.info("Current logged in user is " + loginUser.getUserName());

            logger.info("Creating proxy user.");
            proxyUser = UserGroupInformation.createProxyUser(userToProxy, loginUser);

            for (Token<?> token : loginUser.getTokens()) {
                proxyUser.addToken(token);
            }
        } else {
            proxyUser = UserGroupInformation.createRemoteUser(userToProxy);
        }

        logger.info("Proxied as user " + userToProxy);

        proxyUser.doAs(new PrivilegedExceptionAction<Void>() {
            @Override
            public Void run() throws Exception {
                runHive(args);
                return null;
            }
        });

    } else {
        logger.info("Not proxying. ");
        runHive(args);
    }
}

From source file:com.googlecode.promnetpp.main.Main.java

/**
 * Main function (entry point for the tool).
 *
 * @param args Command-line arguments.//from w ww.j  av a 2 s  .  c  om
 */
public static void main(String[] args) {
    //Prepare logging
    try {
        Handler fileHandler = new FileHandler("promnetpp-log.xml");
        Logger logger = Logger.getLogger("");
        logger.removeHandler(logger.getHandlers()[0]);
        logger.addHandler(fileHandler);
    } catch (IOException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
    String PROMNeTppHome = System.getenv("PROMNETPP_HOME");
    if (PROMNeTppHome == null) {
        String userDir = System.getProperty("user.dir");
        System.err.println("WARNING: PROMNETPP_HOME environment variable" + " not set.");
        System.err.println("PROMNeT++ will assume " + userDir + " as" + " home.");
        PROMNeTppHome = userDir;
    }
    System.setProperty("promnetpp.home", PROMNeTppHome);

    Logger.getLogger(Main.class.getName()).log(Level.INFO, "PROMNeT++ home" + " set to {0}",
            System.getProperty("promnetpp.home"));
    if (args.length == 1) {
        fileNameOrPath = args[0];
        configurationFilePath = PROMNeTppHome + "/default-configuration.xml";
    } else if (args.length == 2) {
        fileNameOrPath = args[0];
        configurationFilePath = args[1];
    } else {
        System.err.println("Invalid number of command-line arguments.");
        System.err.println("Usage #1: promnetpp.jar <PROMELA model>.pml");
        System.err.println("Usage #2: promnetpp.jar <PROMELA model>.pml" + " <configuration file>.xml");
        System.exit(1);
    }
    //We must have a file name or path at this point
    assert fileNameOrPath != null : "Unspecified file name or" + " path to file!";

    //Log basic info
    Logger.getLogger(Main.class.getName()).log(Level.INFO, "Running" + " PROMNeT++ from {0}",
            System.getProperty("user.dir"));
    //Final steps
    loadXMLFile();
    Verifier verifier = new StandardVerifier(fileNameOrPath);
    verifier.doVerification();
    assert verifier.isErrorFree() : "Errors reported during model" + " verification!";
    verifier.finish();
    buildAbstractSyntaxTree();
    Translator translator = new StandardTranslator();
    translator.init();
    translator.translate(abstractSyntaxTree);
    translator.finish();
}

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  w ww .j a  v  a2  s. com
    frame.setVisible(true);
}

From source file:com.arpnetworking.tsdaggregator.TsdAggregator.java

/**
 * Entry point for Time Series Data (TSD) Aggregator.
 *
 * @param args the command line arguments
 *//*from  ww  w.  j a  v a2s .  co m*/
public static void main(final String[] args) {
    LOGGER.info("Launching tsd-aggregator");

    // Global initialization
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(final Thread thread, final Throwable throwable) {
            LOGGER.error("Unhandled exception!", throwable);
        }
    });

    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override
        public void run() {
            final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
            context.stop();
        }
    }));

    System.setProperty("org.vertx.logger-delegate-factory-class-name",
            "org.vertx.java.core.logging.impl.SLF4JLogDelegateFactory");

    // Run the tsd aggregator
    if (args.length != 1) {
        throw new RuntimeException("No configuration file specified");
    }
    LOGGER.debug(String.format("Loading configuration from file; file=%s", args[0]));

    final File configurationFile = new File(args[0]);
    final Configurator<TsdAggregator, TsdAggregatorConfiguration> configurator = new Configurator<>(
            TsdAggregator.class, TsdAggregatorConfiguration.class);
    final ObjectMapper objectMapper = TsdAggregatorConfiguration.createObjectMapper();
    final DynamicConfiguration configuration = new DynamicConfiguration.Builder().setObjectMapper(objectMapper)
            .addSourceBuilder(
                    new JsonNodeFileSource.Builder().setObjectMapper(objectMapper).setFile(configurationFile))
            .addTrigger(new FileTrigger.Builder().setFile(configurationFile).build()).addListener(configurator)
            .build();

    configuration.launch();

    final AtomicBoolean isRunning = new AtomicBoolean(true);
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override
        public void run() {
            LOGGER.info("Stopping tsd-aggregator");
            configuration.shutdown();
            configurator.shutdown();
            isRunning.set(false);
        }
    }));

    while (isRunning.get()) {
        try {
            Thread.sleep(30000);
        } catch (final InterruptedException e) {
            break;
        }
    }

    LOGGER.info("Exiting tsd-aggregator");
}

From source file:com.antelink.sourcesquare.SourceSquare.java

public static void main(String[] args) {

    logger.debug("starting.....");

    final EventBus eventBus = new EventBus();

    AntepediaQuery query = new AntepediaQuery();

    SourceSquareEngine engine = new SourceSquareEngine(eventBus, query);

    ScanStatusManager manager = new ScanStatusManager(eventBus);
    manager.bind();/*from w w w .j av  a2s .co m*/

    TreeMapBuilder treemap = new TreeMapBuilder(eventBus);
    treemap.bind();

    ResultBuilder builder = new ResultBuilder(eventBus, treemap);
    builder.bind();

    final SourceSquareFSWalker walker = new SourceSquareFSWalker(engine, eventBus, treemap);
    walker.bind();

    ServerController.bind(eventBus);
    if (args.length != 0) {
        final File toScan = new File(args[0]);

        if (!toScan.isDirectory()) {
            logger.error("The argument is not a directory");
            logger.info("exiting SourceSquare");
            System.exit(0);
        }

        eventBus.fireEvent(new StartScanEvent(toScan));

        System.setProperty("apple.laf.useScreenMenuBar", "true");
        System.setProperty("com.apple.mrj.application.apple.menu.about.name", "SourceSquare");

        logger.info("Scan complete");
        logger.info("Number of files to scan: " + ScanStatus.INSTANCE.getNbFilesToScan());
        logger.info("Number of files Scanned: " + ScanStatus.INSTANCE.getNbFilesScanned());
        logger.info("Number of files open source: " + ScanStatus.INSTANCE.getNbOSFilesFound());
    } else {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException e) {
            logger.info("Error launching the UI", e);
        } catch (InstantiationException e) {
            logger.info("Error launching the UI", e);
        } catch (IllegalAccessException e) {
            logger.info("Error launching the UI", e);
        } catch (UnsupportedLookAndFeelException e) {
            logger.info("Error launching the UI", e);
        }
        SourceSquareView view = new SourceSquareView();
        SourceSquareController controller = new SourceSquareController(view, eventBus);

        ExitSourceSquareView exitView = new ExitSourceSquareView();
        ExitController exitController = new ExitController(exitView, eventBus);

        exitController.bind();
        controller.bind();
        controller.display();
    }

}

From source file:cytoscape.CyMain.java

License:asdf

/**
 * DOCUMENT ME!/*from w w w.  ja  va  2  s  .  c  o m*/
 * 
 * @param args
 *            DOCUMENT ME!
 * 
 * @throws Exception
 *             DOCUMENT ME!
 */
public static void main(String[] args) throws Exception {
    if (System.getProperty("os.name").startsWith("Mac")) {
        System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Cytoscape");
    }

    CyMain app = new CyMain(args);
}

From source file:gov.nih.nci.cabig.ccts.security.SecureURL.java

/**
 * For testing only...//from  w  w  w . j  a v  a  2 s .com
 */
public static void main(String args[]) throws IOException {
    System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
    System.out.println(SecureURL.retrieve(args[0]));
}

From source file:de.bayern.gdi.App.java

/**
 * @param args the command line arguments
 *///from w ww. j a  v  a 2s  .  com
public static void main(String[] args) {

    Options options = new Options();

    Option help = Option.builder("?").hasArg(false).longOpt("help").desc("Print this message and exit.")
            .build();

    Option headless = Option.builder("h").hasArg(false).longOpt("headless").desc("Start command line tool.")
            .build();

    Option conf = Option.builder("c").hasArg(true).longOpt("config")
            .desc("Directory to overwrite default configuration.").build();

    Option user = Option.builder("u").hasArg(true).longOpt("user").desc("User name for protected services.")
            .build();

    Option password = Option.builder("p").hasArg(true).longOpt("password")
            .desc("Password for protected services.").build();

    options.addOption(help);
    options.addOption(headless);
    options.addOption(conf);
    options.addOption(user);
    options.addOption(password);

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

        if (line.hasOption("?")) {
            usage(options, 0);
        }

        if (line.hasOption("h")) {
            // First initialize log4j for headless execution
            final String pid = getProcessId("0");
            System.setProperty("logfilename", "logdlc-" + pid + ".txt");
        }

        // use configuration for gui and headless mode
        initConfig(line.getOptionValue("c"));

        if (line.hasOption("h")) {
            System.exit(Headless.main(line.getArgs(), line.getOptionValue("u"), line.getOptionValue("p")));
        }

        startGUI();

    } catch (ParseException pe) {
        System.err.println("Cannot parse input: " + pe.getMessage());
        usage(options, 1);
    }
}

From source file:com.projity.pm.graphic.gantt.Main.java

public static void main(String[] args) {
    System.setProperty("com.apple.mrj.application.apple.menu.about.name",
            Environment.getStandAlone() ? "OpenProj" : "Project-ON-Demand");
    System.setProperty("apple.laf.useScreenMenuBar", "true");
    Locale.setDefault(ConfigurationFile.getLocale());
    HashMap opts = ApplicationStartupFactory.extractOpts(args);
    String osName = System.getProperty("os.name").toLowerCase();
    if (osName.startsWith("linux")) {
        String javaExec = ConfigurationFile.getRunProperty("JAVA_EXE");
        //check jvm
        String javaVersion = System.getProperty("java.version");
        if (Environment.compareJavaVersion(javaVersion, "1.5") < 0) {
            String message = Messages.getStringWithParam("Text.badJavaVersion", javaVersion);
            if (javaExec != null && javaExec.length() > 0)
                message += "\n" + Messages.getStringWithParam("Text.javaExecutable",
                        new Object[] { javaExec, "JAVA_EXE", "$HOME/.openproj/run.conf" });
            if (!opts.containsKey("silentlyFail"))
                JOptionPane.showMessageDialog(null, message, Messages.getContextString("Title.ProjityError"),
                        JOptionPane.ERROR_MESSAGE);
            System.exit(64);//  www  . j a v  a  2  s .  c  om
        }
        String javaVendor = System.getProperty("java.vendor");
        if (javaVendor == null || !(javaVendor.startsWith("Sun") || javaVendor.startsWith("IBM"))) {
            String message = Messages.getStringWithParam("Text.badJavaVendor", javaVendor);
            if (javaExec != null && javaExec.length() > 0)
                message += "\n" + Messages.getStringWithParam("Text.javaExecutable",
                        new Object[] { javaExec, "JAVA_EXE", "$HOME/.openproj/run.conf" });
            if (!opts.containsKey("silentlyFail"))
                JOptionPane.showMessageDialog(null, message, Messages.getContextString("Title.ProjityError"),
                        JOptionPane.ERROR_MESSAGE);
            System.exit(64);
        }
    }

    boolean newLook = false;
    //      HashMap opts = ApplicationStartupFactory.extractOpts(args); // allow setting menu look on command line - primarily for testing or webstart args
    log.info(opts);
    //      newLook = opts.get("menu") == null;

    Environment.setNewLook(newLook);
    //      if (!Environment.isNewLaf()) {
    //         try {
    //            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    //         } catch (Exception e) {
    //         }
    //      }
    ApplicationStartupFactory startupFactory = new ApplicationStartupFactory(opts); //put before to initialize standalone flag
    mainFrame = new MainFrame(Messages.getContextString("Text.ApplicationTitle"), null, null);
    boolean doWelcome = true; // to do see if project param exists in args
    startupFactory.instanceFromNewSession(mainFrame, doWelcome);
}