• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

log4j.properties

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?





 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you trying to access it?

And why, since if it's on the classpath Log4J will use it automatically?
 
Kevin Eddy
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

suggestions?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess my question is still "why are you trying to access the Log4J config file programatically"? Do you need to?
 
Kevin Eddy
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand where your going with your question. What other alternative is there?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Log4J picks up config files on the classpath automatically:

I wrote:And why, since if it's on the classpath Log4J will use it automatically?

 
Kevin Eddy
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I don't have to use the propertyConfigurator? Is that what you are saying?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Kevin Eddy
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

log4j.appender.rollingFile=org.apache.log4j.RollingFileAppender
log4j.appender.rollingFile.File=logs/SolrIndex.log
log4j.appender.rollingFile.MaxFileSize=2MB
log4j.appender.rollingFile.MaxBackupIndex=2
log4j.appender.rollingFile.layout = org.apache.log4j.PatternLayout
log4j.appender.rollingFile.layout.conversionPattern=%p %d %c – %m%n
log4j.rootLogger = DEBUG, rollingFile

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.

Kevin.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic