0

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?

Tausif Baber
  • 500
  • 2
  • 8
  • 23
  • log4j searches for config files in the classpath, so putting log4j.properties in the "Source packages" IDE project tree folder should work (iirc NetBeans includes files in the generated jar) – mjn Apr 04 '11 at 12:29

2 Answers2

0

If you run your program with an IDE such as NetBeans, check an extra time that the file is in the output directory of the IDE. Usually, log4j looks for this file on the classpath, so you must make sure that NetBeans actually copies it there. Your IDE will most likely set it's own output directory as part of the classpath, so i think you have (at least) two options here: either to add the directory where you've put log4j.properties to the classpath, or to make sure it is copied to the IDE:s output directory. Good luck!

AndersG
  • 365
  • 4
  • 12
  • Thanks for answer but i already know these things, so please read the question again. The problem is that it always throws the exception file not found even if you provide any path (C:/some_folder/filename). – Tausif Baber Apr 04 '11 at 11:22
  • Can you post the directory structure of your project? – AndersG Apr 04 '11 at 11:44
  • for development: src->META-INF->log4j.properties ============== buildpath: build->classes->META-INF->log4j.properties =========== i can access the file by File object. so there is nothing wrong with filepath etc. there might be some hard coded value for log4j configure function or its not compatible with j2se 6 with netbeans 6.9) – Tausif Baber Apr 04 '11 at 11:52
0

it worked if i load the properties from the properties file

PropertyConfigurator.configure((new Properties()).load(new FileInputStream ("log4j.properties")));
Tausif Baber
  • 500
  • 2
  • 8
  • 23