Using external properties files in weblogic

前端 未结 8 1061
被撕碎了的回忆
被撕碎了的回忆 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:04

    There are ways to read properties file in Java from weblogic classpath

    One (Properties file located in the weblogic domain): Drop the properties file inside the Domain directory. This way the properties file is added to the weblogic classpath automatically and we can read from Java using resourceAsStream.

    Two (Properties file from a User defined location):The advantage with this approach is that the property file can reside outside the JAR or EAR file and can be modified conveniently.

    package com.test;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Properties;
    
    public class PropertyFileExample {
    
    private static Properties prop;
    
    public static void myMethod() {
    
      InputStream is = null;
    
      try {
    
        prop = new Properties();
    
        String propFilePath = System.getProperty(“propFileLocation“);
    
        InputStream iStream =     PropertyFileExample.class.getClassLoader().getResourceAsStream(propFilePath);
    
        //Note that the propFilePath is a -Dparam defined below in the setDomainEnv
        prop.load(iStream);
        prop.getProperty(“dbuser”);
    
      } catch (FileNotFoundException e) {
    
        e.printStackTrace();
    
      } catch (IOException e) {
    
        e.printStackTrace();
    
      }
    }
    }
    

    In the weblogic setDomainEnv (under bin) => we need to pass the location of the property file as a -D argument to JAVA_OPTIONS

    set JAVA_OPTIONS=%JAVA_OPTIONS% -DpropFileLocation =/dev/file/properties/some.properties
    

提交回复
热议问题