Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with log4j properties file path

 
Tushar Madhukar
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have created an standalone application that is completely bundled in jar file. I would like to use log4j for logging purposes.

Is it possible to package the log4j.properties file in the jar itself, so that the PropertyConfigurator can find it at runtime? I tried putting the properties file at the root of the jar, but log4j is not able to find it there.

Can anybody suggest how can this be done?

Thx
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I havent tried this, but i think the log4j.properties file will have to be in the same folder as the jar file. However, i do think that placing the log4j.properties file in the jar should have worked. To see how log4j is trying to look for the properties file, you can try out the following:

Know how log4j tries to configure itself
 
Ruth J
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use an external log4j.properties file that is not in your jar.

Do this: In your manifest set the class-path:

Example:
Class-Path: ./WEB-INF/lib/log4j-1.2.9.jar ./WEB-INF/lib/

That second entry is going to be where you put the log4j.properties file in relation to your jar.

Don't package the log4j.properties file in your jar.

Execute your jar like: java -jar myapp.jar (don't put any classpath options)

Now you can change the settings in your log4j.properties file and not have to repackage it in your jar.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic