17

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 files. In Jboss I can just put the properties files into $JBOSS_HOME/server/default/conf, and they are loaded onto the system classpath and I can access them without any problems. I was able to put shared libraries into $MIDDLEWAREHOME/user_projects/domains/mydomain/lib and they were loaded into the system classpath without any problems but I am unable to load properties files.

Does anyone know how to include external properties files in Weblogic?

Thanks,

1

8 Answers 8

16

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.

0
2

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

1
  • 1
    Do I have to activate this behavior somewhere? I have a fresh WebLogic 12c development installation on Windows XP running, which is not picking upp my logback.xml from domain directory!
    – Matthias B
    Commented Apr 18, 2013 at 9:33
2

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
2
  • 1
    please add more information like code example for your answer. Commented Mar 25, 2014 at 23:35
  • Code and detailed explanation is in the link. Did you mean it should instead have been posted here?. Commented Mar 25, 2014 at 23:39
1

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.

1
  • if its linux what to be changed in .sh file Commented Mar 7, 2022 at 14:13
1

The most flexible way is to use weblogic deployment plans and Generic File Loading overrides

External properties file with Weblogic

http://docs.oracle.com/cd/E21764_01/web.1111/e13702/config.htm#DEPGD188

0

Although it may be a little extra effort, if you put the files into a JAR before dropping them into that lib directory, that should work.

1
  • I did that, I put the newly created jar file(containing my properties file) in a lib folder defined on the classpath. This worked, and I figured it would, but it is not ideal to have to jar/unjar these config files when a change needs to be made. This is only a few steps better than including the properties file in my ear file somewhere. For now it works, so I'm going to go with it while looking for a better solution.
    – broschb
    Commented Aug 7, 2009 at 21:11
0

You can look at your setDomainEnv.cmd (Windows) or setDomainEnv.sh (Unix/Linux) script in your domain files and see what locations are added in the CLASSPATH for your domain. Then just choose one folder and place the properties file there, if you want a specific location for your properties file just edit the script.

1
  • I did that, and I put the files in a folder that is added to classpath, it is not picking up any properties files. It is however picking up the jar files that I put in that same directory. I'm not sure why the properties files are not getting picked up.
    – broschb
    Commented Aug 7, 2009 at 21:10
0

that was my solution:

ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");

        InputStream is = null;

        String urlExte = System.getenv("DOMAIN_HOME")+"/properties/SmsBalanceadoWS/";


        org.springframework.core.io.Resource resource = ctx.getResource( "file:"+urlExte+"/application.properties");
        try {
            is = resource.getInputStream();
        } catch (IOException e) {
            LOGGER.debug("ERROR"+ e.getMessage());
        }
2
  • 2
    Please add explanation. see stackoverflow.com/help/how-to-answer
    – Ori Marko
    Commented Nov 21, 2017 at 13:27
  • he is trying to get domain_home OS environment variable value, and assumes a properties folder exists there, unfortunately I dont see it being set in my jvm, but I do see user.dir set to /opt/oracle/config/domains/abcd where abcd is my domain name Commented Apr 9, 2018 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.