Reputation: 31
I'm trying to start up a java application from command line with the hope that it'll pick up the log4j config files in a different folder. Here is my folder structure:
/app
-> app base folder
/app/config
-> stores custom config files including log4j
/app/lib
-> stores all the jars
However when I try running the program from /app
for some reason log4j is not initializing properly:
-bash-4.2# pwd
/app
-bash-4.2# java -cp config:lib/* -Xmx1024M className
log4j:WARN No appenders could be found for logger(org.springframework.beans.factory.xml.XmlBeanDefinitionReader).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Surprisingly, if I move the config folder to /lib
, and then try to start up the java program from there, it all seems to be working:
(updated folder structure):
/app
-> app base folder
/app/lib
-> stores all the jars
/app/lib/config
-> stores custom config files including log4j
Output:
-bash-4.2# pwd
/app/lib
-bash-4.2# java -cp config:* -Xmx1024M className
<Expected log message now shows up>
Inside my code I used PropertyConfigurator
to load the config file:
PropertyConfigurator.configureAndWatch(loggingConfigFile)
Where logProperties
is defined as
val loggingConfigFile = "config/custom.logging.properties"
Originally I thought the problem with the first scenario was with some kind of pathing issue, however when printing out System.getProperty("user.dir")
during run time it seems that the program was indeed running under /app
and that it should be able to load the config file from the defined path (i.e. /app/config/custom.logging.properties
). Is there anything wrong with the setup?
Upvotes: 0
Views: 282
Reputation: 71
EDIT: Application tries to find property files at run time path.
It's working in my case
For access properties value. Make ResourceBundle Object. Ex.:
private final ResourceBundle objRbLdap = ResourceBundle.getBundle("prperties file name");
Upvotes: 1