linux中,运行java程序装载linux指定目录下的Properties文件

在linux脚本中,指定应用的properties文件,调用java应用去读取properties文件

linux脚本:
---------------
export CFG_ROOT=/a/b/c/app.properties
export JAVA_CMD=$JAVA_HOME/bin/java
export CLASSPATH=...
export JAVA_CMD=$JAVA_HOME/bin/java
export JAVA_LIB=a.b.appMain
BATCH_SIZE =10000000
$JAVA_CMD -Xmx6000m -classpath "$CLASSPATH" $JAVA_LIB $1 $2 $BATCH_SIZE #>> $LOGFILE

 java代码片段:
-------------------------
    public LoadConfiguration(String fileName){
    String configurationDir = System.getenv(" CFG_ROOT ");
    if ("".equalsIgnoreCase(ConfigurationDir.trim())){
    logger.error("CPSCFG_ROOT hasn't been set correct!");
    return;
    }
        propertie = new Properties();
        try {
        if (ConfigurationDir.indexOf(ConfigurationDir.length()-1) != '/'){
        ConfigurationDir = ConfigurationDir + "/";
        }
            inputFile = new FileInputStream(ConfigurationDir+fileName);
            propertie.load(inputFile);
            inputFile.close();
        } catch (FileNotFoundException ex){
            System.out.println("Read Properties File --->Failure! Reason: File Path Error or File not exist! Name:" + ConfigurationDir+"/"+fileName);
            ex.printStackTrace();
        } catch (IOException ex){
            System.out.println("Load Configuration File--->Failure! Name:" + ConfigurationDir+"/"+fileName);
            ex.printStackTrace();
        }
    }

你可能感兴趣的:(java,linux,properties)