Java Properties Load loadSystemPropertiesFromPropertiesResource(String propertiesResourceName)

Here you can find the source of loadSystemPropertiesFromPropertiesResource(String propertiesResourceName)

Description

Load the specified properties file from the classpath, and add every property as a system property.

License

BSD License

Declaration

public static void loadSystemPropertiesFromPropertiesResource(String propertiesResourceName) 

Method Source Code

//package com.java2s;
/*L//from w  w  w. j a  v a2  s  .c  o m
 *  Copyright SAIC, Ellumen and RSNA (CTP)
 *
 *
 *  Distributed under the OSI-approved BSD 3-Clause License.
 *  See http://ncip.github.com/national-biomedical-image-archive/LICENSE.txt for details.
 */

import java.util.Properties;
import java.net.URL;

public class Main {
    /**
     * Load the specified properties file from the classpath, and add every property
     * as a system property.  This is typically used to assist testing.
     *
     * <P>If resrouce is not to be found, a RuntimeException will be thrown.
     */
    public static void loadSystemPropertiesFromPropertiesResource(String propertiesResourceName) {
        try {
            Properties props = new Properties();
            URL url = ClassLoader.getSystemResource(propertiesResourceName);
            props.load(url.openStream());
            for (Object key : props.keySet()) {
                System.setProperty((String) key, (String) props.get(key));
            }
        } catch (Throwable e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
}

Related

  1. loadPropertiesFromResource(ClassLoader clsLoader, String resourcePath)
  2. loadPropertiesFromResource(String name)
  3. loadPropertiesFromResources(Class cls, String[] resources)
  4. loadPropertiesFromString(String propertiesString)
  5. loadPropertiesResources(String name)