Wednesday, March 1, 2017

set properties file @ Weblogic box

setDomainEnv.sh file@ FusionMW/user_projects/ADF_domain/bin @ line no. around 324

JAVA_PROPERTIES="-Dwls.home=${WLS_HOME} -Dweblogic.home=${WLS_HOME} -DAPP_PROPERTY_FILE=/app/WL12c/app/oracle/product/fmw12cr3/app.properties


app.properties is the file like key value pairs--

e.g.

maxFileSize=5240000
maxCommentsLength=242
dataSourceLocation=jdbc/HRDS
maxErrorsAllowed=50
# printDebugInfo should be set to boolean values only (true or false)
printDebugInfo=true


How to access this in JAVA/Servlet

public class ReadPropertiesFile {
    
    int maxFileSize;
    int maxCommentsLength;
    int maxErrorsAllowed;
    boolean debug;
    String dataSourceLocation;
    Properties prop;
    //String propsFileName = "brvo.properties";
    
    public ReadPropertiesFile(){
       prop = new Properties();
        
        try {
            //this.prop.load(new FileInputStream(fileName));
           prop.load(new FileInputStream(System.getProperty("APP_PROPERTY_FILE")));
           System.out.println("inside ReadPropertiesFile -- about to print property file values....");
           System.out.println(prop.getProperty("dataSourceLocation"));
           System.out.println(prop.getProperty("maxFileSize"));
           System.out.println(prop.getProperty("maxErrorsAllowed"));
        //            System.out.println("Max File Size: " + maxFileSize);
        } catch (Exception e) {
            System.out.println("Error reading properties file: " + System.getProperty("APP_PROPERTY_FILE"));
            System.out.println(e.getMessage());
        }
        
    }
    

    public void setMaxFileSize() {
        int fileSize;
        fileSize = Integer.parseInt(prop.getProperty("maxFileSize"));
        this.maxFileSize = fileSize;
    }

    public int getMaxFileSize() {     
        this.maxFileSize = Integer.parseInt(prop.getProperty("maxFileSize"));
        return maxFileSize;
    }

    public void setMaxCommentsLength() {
        this.maxCommentsLength = Integer.parseInt(prop.getProperty("maxCommentsLength"));
    }

    public int getMaxCommentsLength() {
        this.maxCommentsLength = Integer.parseInt(prop.getProperty("maxCommentsLength"));
        return maxCommentsLength;
    }

    public void setDataSourceLocation() {
        this.dataSourceLocation = prop.getProperty("dataSourceLocation");
    }

    public String getDataSourceLocation() {
        this.dataSourceLocation = prop.getProperty("dataSourceLocation");
        return dataSourceLocation;
    }

    public void setMaxErrorsAllowed() {
        this.maxErrorsAllowed = Integer.parseInt(prop.getProperty("maxErrorsAllowed"));
    }

    public int getMaxErrorsAllowed() {
        this.maxErrorsAllowed = Integer.parseInt(prop.getProperty("maxErrorsAllowed"));
        return maxErrorsAllowed;
    }

    public void setDebug() {
        String booleanValue = prop.getProperty("printDebugInfo");
        if(booleanValue.equals("true")){
            this.debug = true;
        }else this.debug = false;
    }

    public boolean isDebug() {
        return debug;
    }  
}

No comments:

Post a Comment