I am now creating a standalone java application which needs to be run as an executable jar.I have configured log4j for proper logging. It writes all the log files when running the application from eclipse.But when I ran the executable jar it comes up with a warning as ** log4j:WARN No appenders could be found for logger log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. ** Can someone please suggest how to solve the issue?
2 Answers
You may not have a valid or correct configuration. Add this to your main method.
BasicConfigurator.configure();
Failing that , the properties file may not be set up properly if you are using maven in the pom.
The other case is that you have two different logging frameworks in use. Use one or the other.
Another try would be doing something like this to set the property or log4j rootlogger :
Properties prop = new Properties();
prop.setProperty("log4j.rootLogger", "WARN");
PropertyConfigurator.configure(prop);
Also you can try adding a system property to the command line when you start Java:
-Dlog4j.configuration=file:///path/to/your/log4j.properties
Last ditch effort is:
Move Your log4j.properties file into the src folder. Open Windows explorer, browse to the directory where your project resides in. Browse to bin directory and delete all the folders with in it.
Now in eclipse click project-->clean-->OK
This would force it to build the project again,all the contents delete from bin directory will be recreated. Then use the executable jar again when you newly build it.