File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Open Source Projects and the fly likes Problem with log4j properties file path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Problem with log4j properties file path" Watch "Problem with log4j properties file path" New topic

Problem with log4j properties file path

Tushar Madhukar
Ranch Hand

Joined: May 03, 2006
Posts: 36

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 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?

Jaikiran Pai

Joined: Jul 20, 2005
Posts: 10441

I havent tried this, but i think the file will have to be in the same folder as the jar file. However, i do think that placing the 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

[My Blog] [JavaRanch Journal]
Ruth J

Joined: Sep 04, 2008
Posts: 1
You can use an external file that is not in your jar.

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

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

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

Don't package the 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 file and not have to repackage it in your jar.
I agree. Here's the link:
subject: Problem with log4j properties file path
jQuery in Action, 3rd edition