I've built an executable jar that contains the log4j.properties file. When I execute the .jar, it cannot find the .properties file. I've tried many different variations on the path. What does work is hardcoding the path from the root drive. C:/blah/blah/log4j.properties.
I know this is probably a really dumb question but is there not a way to reference the log4j.properties that's inside the executable?
David Newton wrote:How are you trying to access it?
And why, since if it's on the classpath Log4J will use it automatically?
I have a jar I run from the prompt.
I'm trying to access the log4j.properties file that's inside of the jar. But I've not been able to pass the correct path to the PropertyConfigurator.
The path to the properties file is myJar-with-dependencies.jar/META-INF/log4j.properties.
I just looked at my MANIFEST.MF file and it's not on the class path. I guess this is why it can't find my properties file? I'm not entirely sure how to go about that as I'm using Maven for this project and I'm learning more about Maven as I go. I can pass a hard coded path to a log4j.properties file that lives outside the jar and the PropertyConfigurator will find it no problem. But I thought it would be cleaner If I could access the log4j.properties inside of the jar.
Goodness. I don't know what you're doing with the config file, which is why I was asking what you were doing with the config file and why you needed it. Log4J will pick up configuration files on the classpath automatically.
David Newton wrote:Goodness. I don't know what you're doing with the config file, which is why I was asking what you were doing with the config file and why you needed it. Log4J will pick up configuration files on the classpath automatically.
Well, the config file specifies my rolling appenders etc and also the the log file. I thought, and maybe erroneously on my part, the proper way to do that was to use
PropertyConfigurator.configure("META-INF/log4j.properties");
Is that the wrong approach to setting up log4j?
I don't know if this helps or not but here's the log4j.properties file contents.
I mean, the file exists inside of my jar. I just really want to know how to pick it up from my jar as opposed to the file not only being in my jar, but then me having to hand move it to where the thing is going to be deployed and then specifying something like this:
PropertyConfigurator.configure("C:/workspace/solr-maven/src/main/resources/META-INF/log4j.properties")
to be able to pick up the log4j file.
Is it "wrong"? Of course not, there may well be reasons why someone would do it like that. I essentially never do, I just put it on my classpath, because Log4J will pick up configuration files on the classpath automatically.
Post by:autobot
These are the worst of times and these are the best of times. And this is the best tiny ad:
a bit of art, as a gift, that will fit in a stocking