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,

broschb
  • 4,976
  • 4
  • 35
  • 52
  • Below is the the question which is mostly similar to this question as a concept wise. The anwser shows how to get domain path/classpath. http://stackoverflow.com/questions/41352916/not-able-to-load-external-properties-files-with-springboot-in-weblogic/41364735#41364735 – bvyas Dec 28 '16 at 16:27

8 Answers8

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.

broschb
  • 4,976
  • 4
  • 35
  • 52
2

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

suresh
  • 31
  • 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 Apr 18 '13 at 09: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
Smajl
  • 7,555
  • 29
  • 108
  • 179
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.

net user
  • 573
  • 2
  • 8
  • 21
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

Community
  • 1
  • 1
Kalpesh Soni
  • 6,879
  • 2
  • 56
  • 59
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.

Adam Batkin
  • 51,711
  • 9
  • 123
  • 115
  • 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 Aug 07 '09 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.

victor hugo
  • 35,514
  • 12
  • 68
  • 79
  • 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 Aug 07 '09 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());
        }
Yurifull
  • 373
  • 2
  • 5
  • 2
    Please add explanation. see https://stackoverflow.com/help/how-to-answer – Ori Marko Nov 21 '17 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 – Kalpesh Soni Apr 09 '18 at 19:26