2
votes

I have a simple application that uses Spring to load a properties file from the classpath. When deploying this application to WebSphere Liberty 8.5.5 it results in FileNotFoundException.

nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/myprops.properties]

Here is my spring @Configuration class:

@Configuration
@Profile("dev")
@PropertySource("classpath:/myprops.properties")
public class AppConfigDev extends AppConfig {
  ...
}

I am wondering where in the Liberty directory structure should my properties file reside?

2
In WEB-INF/classes or in a jar in WEB-INF/lib should work. Where is the file? - Alasdair
I've since changed this to use "file:myprops.properties" as I do not want to source the classpath. In Liberty I am curious what is the current path when sourcing a file this way using relative path. - sleepyj
The current working directory will be the server output dir. - Alasdair

2 Answers

0
votes

The use of prefix classpath: in your annotation signifies that the given property file would be picked up from WebSphere's, well, classpath, via a ClassLoader.getResources(...) call.

Ref: http://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/html/resources.html#resources-classpath-wildcards

You will need to create a jar of all your properties files for Websphere Liberty to be able to load them.

Ref: 1. https://developer.ibm.com/answers/questions/13384/websphere-liberty-8-5-setting-java-classpath.html
2. Websphere Liberty 8.5: Setting Java classpath

0
votes

You can set the name/directory of your files in a file named jvm.options and put it in your ${server.config.dir}/jvm.options

Specific example :
In the file: ${server.config.dir}/jvm.options
Add the following line: -DAPP_ENV=PROD
Access the value with: System.getProperty("APP_ENV"); -> PROD