Using external properties files in weblogic

前端 未结 8 1067
被撕碎了的回忆
被撕碎了的回忆 2020-12-24 14:53

I am working on deploying a J2ee application that I have previously been deploying in JBOSS into Weblogic 10.3.1.0. I am running into an issue with external properties file

8条回答
  •  佛祖请我去吃肉
    2020-12-24 15:07

    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.

提交回复
热议问题