Search code examples
log4jnetbeans-6.9java

how to use log4j with Netbeans 6.9.1 for Java desktop application


I am trying to use log4j for my Java desktop application that i am developing using Netbeans IDE 6.9.1. I have log4j.properties file in META-INF folder for logging during development. I also tried to put it along with the executable jar(after installation) but both of them did not work. It also throws exception when i call the method.

PropertyConfigurator.configure(filepath);

and it always throws this exception irrespective of the location of log.properties file

java.io.FileNotFoundException: META-INF\log4j.properties (The system cannot find the path specified)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:106)
        at java.io.FileInputStream.<init>(FileInputStream.java:66)
        at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:306)
        at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:324)
        at fi.xmldation.common.SharedMethods.readSettingsFile(SharedMethods.java:43)

Is it a bug in the IDE or I am doing something wrong?


Solution

  • it worked if i load the properties from the properties file

    PropertyConfigurator.configure((new Properties()).load(new FileInputStream ("log4j.properties")));