Saturday, April 28, 2012

Properties file outside EAR


If properties file is placed outside EAR, then there won't be any need to build ear everytime.

Steps:
1. Place the properties file/files at any location on server.
2. Include the location of properties file in classpath.
e.g. If weblogic server is used, you can make entry in server startup script.
set CLASSPATH=(PATH of .properties file without braces);%CLASSPATH%
We can then change properties file & even without building ear, new properties file will be used.

Note: If the logic is to load properties file only once, in that case server restart is needed.

Finally, simple java method to load properties file can be used:
    public static void loadPropertiesBundle(){
        Properties propertiesBundle = new Properties();
        InputStream stream = Thread.currentThread().getContextClassLoader()
                                   .getResourceAsStream("PropertiesFileName.properties");
        try {
            propertiesBundle.load(stream);
        } catch (IOException e) {
            adfLogger.log(ADFLogger.ERROR, "Error getting Property file :" + e.getStackTrace());
        }
    }

No comments:

Post a Comment