java - java - Log4j eclipse class not found - answerstu - answerstu

java - Log4j eclipse class not found

(OS: Windows 10)

Hi all,

In order, i

1- Downloaded the last version of log4j2, unzipped it in .../Program Files/Java folder

2- Added the jar files (api e core jars) to my project folder in eclipse and added them to the project build path.

3- Created the file with the following instructions, and added it to the build path

log4j.rootlogger=DEBUG, toConsole

log4j.appender.toConsole.layout.ConversionPattern=%d[HH:mm:ss] %5p [%t] - %c.%M - %n%N

4- Wrote a simple code to test the library

import org.apache.log4j.Logger;

public class Log4j {

    private static final Logger log = Logger.getLogger(Log4j.class);

    public static void main(String[] args) {"test");


Once i run Log4j, i got this exception handler in eclipse console:

<terminated> Log4j[Java Application] C:\Program files\Java\jre1.8.0_161\bin\javaw.exe

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/logging/log4j/spi/LoggerContext
    at Log4j.<clinit>(
Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.spi.LoggerContext
    at Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 1 more

In the past days i have tried installing log4j several times with no success, just today i finally set up successfully the library, so i think that the problem could be about some collision with previous installations, even if i have checked also for these.

Thank you for the help.

1 Answer

  1. Quentin- Reply


    You will have to get log4j adapter to use those methods. Try having log4j dependency/jar in the project and trying it out.


Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>