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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.