0

I am trying to configure log4j for one of my web projects. For that I want to read the log4j.properties file. Below is the code

private URL url;
private File file;
file = new File(url.getPath());
DOMConfigurator.configure(url);

Following is the error
Exception in thread "Thread-1" java.lang.NullPointerException

Then I try to give path of where to file is located to the url command

private URL url= new URL("file:/E:/work/workspace/dvddao/WEB-INF/classes/log4j.properties");
private File file;
file = new File(url.getPath()); 
DOMConfigurator.configure(url);

This time I get MalformedURLException compile error

Default constructor cannot handle exception type MalformedURLException thrown by implicit super constructor. Must define an explicit constructor

Anybody can please give a solution to this. Or an alternate solution to get the url for a properties file

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by __avd
0

You should post your web question in JSP forum. However, use getRealPath() method of ServletContext to form a file path. You may also use Properties class for the same.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.