External properties file with Weblogic

前端 未结 5 649
我寻月下人不归
我寻月下人不归 2020-12-16 21:33

I\'m looking for the best way to use an external properties file with an application that is going to be deployed on Weblogic 10.3 server. I read a number of articles on the

5条回答
  •  被撕碎了的回忆
    2020-12-16 22:22

    You can set a directory on the classpath and Place your custom properties file in that folder/directory. So that, the entire directory along with property file will be on classpath. To set the directory on the classpath in weblogic 10.3.x

    • Create a folder in %DOMAIN_HOME%\config\ folder. example appConfig.
    • Place your custom property file (Let's say config.properties) in appConfig directory/folder.
    • Modify the setDomainEnv.cmd (Windows) to include appConfig in the classpath by setting %DOMAIN_HOME%\config\appConfig as value to EXT_POST_CLASSPATH(this variable is already defined in the setDomainEnv.cmd file) variable as below:

      set EXT_POST_CLASSPATH=%EXT_POST_CLASSPATH%;%DOMAIN_HOME%\config\appConfig
      

    You can access that file in you java code as below:

        InputStream inputStream = Thread.currentThread ().getContextClassLoader().getResourceAsStream ("config.properties");
        Properties prop = new Properties();
        prop.load(inputStream);
        String value = prop.getProperty("key");
    

    Hope this helps.

提交回复
热议问题