Using external properties files in weblogic

I figured this out and have it working the way I would expect. First I did try the suggestions as above. If i added a folder to my classpath, or put the properties files in a folder on my classpath, the jars in the file were picked up, but not properties files. If i put my properties files in a jar, and put them in a folder on my classpath everything worked. But I did not want to have jar my files everytime a change was made. The following works in my env.

If i place the properties files in %WEBLOGIC_HOME%/user_projects/domains/MYDOMAIN then they are getting picked up, without having to be placed in a jar file.


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

In weblogic jars will be loaded from the lib and the non jar files will be loaded from the domain folder