It's great that you got it working, but it doesn't appear you fully understand 
why...

configure(String) [1] takes a java.io.File path.  Given that you have provided a
relative path, rather than a fully qualified one, location of the file is going 
to
be relative to the directory from which you started your JVM.  In your case, it
happens to be the same directory in which your Jar file exists.  But you can't
depend on this because your JVM may be started from another directory and this
relative location may become invalid.  And you generally want to avoid the File
system anyway in your Java programs to keep them from being coupled to a
particular environment setup.  For these reasons, I suggest that you use a URL 
[2]
instead and load your config file from the classpath, e.g.,....

URL url =
getClass().getClassLoader().getResource("com/mypackage/log4j-config-file.properties");
PropertyConfigurator.configure(url);


But lets step back for a second.  Unless you are doing something special as far 
as
loading the config file, there's no reason you can't rename your config file to
"log4j.properties".  This will get picked up automatically without you having to
manually configure Log4j.  Just place it in the root package on your classpath 
and
it will get picked up (unless log4j.xml also exists, in which case it will be 
used
in preference to log4j.properties).

The other option, which also avoids manual, programmatic, configuration is to 
set
the property "log4j.configuration", e.g.,....

Example of a URL on Windows...
-Dlog4j.configuration=file:/C:/some/path/to/my/log4j-config-file.properties

Example of a URL on UNIX...
-Dlog4j.configuration=file:/some/path/to/my/log4j-config-file.properties



[1]
http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PropertyConfigurator.html#configure%28java.lang.String%29
[2]
http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PropertyConfigurator.html#configure%28java.net.URL%29


Jake

On 10/8/2010 9:45 AM, Don Raikes wrote:
> Christian,
> 
> Thanks, with the -Dlog4j.debug, I was able to figure out that log4j was 
> looking for a default log4j.xml file which I do not have, but I then copied 
> the a11yMonitor-log4j.properties into the same folder as my test 
> application's jar file  and that worked.  Getting log4j output now!
> 
> -----Original Message-----
> From: Christian Grobmeier [mailto:grobme...@gmail.com] 
> Sent: Thursday, October 07, 2010 10:40 PM
> To: Log4J Users List
> Subject: Re: locating my log4j.properties file
> 
> Hello
> 
> start your programm with:
> -Dlog4j.debug
> 
> This will show you information were it looks for your properties file.
> It usually helps me in this case
> Cheers
> Christian
> 
> On Fri, Oct 8, 2010 at 12:39 AM, Don Raikes <don.rai...@oracle.com> wrote:
>> Hello,
>>
>> I have a java project which I compile and then package in a jar file which 
>> goes into my jdk_home\jre\lib\ext folder (it is an extension to my jdk).
>>
>> In the main class of my application I tell log4j to use a specific 
>> log4j.properties file
>>
>> PropertyConfigurator.configure("a11yMonitor-log4j.properties");
>>
>> Where do I actually place the a11yMonitor-log4j.properties file?
>>
>> I tried in jdk_home\jre\lib and jdk_home\jre\lib\ext but both times I tried 
>> to run my extension, I get a message saying that log4j cannot find the 
>> properties file.
>>
>> Any help would be greatly appreciated.
>>
>> --
>> Sincerely,
>>
>> HYPERLINK "http://www.oracle.com"; \nOracle
>> Donald Raikes | Accessibility Specialist
>> Phone: HYPERLINK "tel:+16028246213"+16028246213 | Mobile: HYPERLINK 
>> "tel:+15202717608"+15202717608 | VOIP: HYPERLINK 
>> "tel:+16028246213"+16028246213
>> Oracle JDeveloper Quality Assurance
>> | Tucson, Arizona
>>
>> HYPERLINK "http://www.oracle.com/commitment"; \nGreen Oracle      Oracle is 
>> committed to developing practices and products that help protect the 
>> environment
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
> 
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org

Reply via email to