How to fix this Log4J import error (related to Classpath too)?

When I run the following simple log4J example, I get an error:

import org.apache.logging.log4j.core.*;
import java.io.*;
import java.sql.SQLException;
import java.util.*;

public class log4jExample{
  /* Get actual class name to be printed on */
  static Logger log = Logger.getLogger(
                      log4jExample.class.getName());

  public static void main(String[] args)
                throws IOException,SQLException{

     log.debug("Hello this is an debug message");
     log.info("Hello this is an info message");
  }
}

and the error is read:

Error: package org.apache.logging.log4j.core does not exist
Error: cannot find symbol
  symbol:   class Logger
  location: class log4jExample
File: C:\Users\adel\Desktop\various_topics\JavaProjects\log4jExample.java  [line: 10]
Error: cannot find symbol
  symbol:   variable Logger
  location: class log4jExample

So, I believe that I correctly added log4J to the classpath, as shown below:

enter image description here

And I extracted the jarfile log4j-core-2.0-beta4.jarfrom the apache directory like this:

enter image description here

I'm not sure what is going on - how does the import statement work? For example, an online example tells me:

import org.apache.log4j.Logger;

but what if my directory structure looks like this:

\ Apache-log4j-2,0-beta4-bin \ org \ Apache \ Logging \ log4j \ kernels \ Logger.java

Should I say:

import org.apache.logging.log4j.core.Logger;

instead

+5
source share
2 answers

, API, Core . . , , import org.apache.logging.log4j.Logger;, Logger API.

Log4j 2 ( Log4j 1.x, ) -:

API

API Log4j , , , . Log4j .

+11

, log4j 2.0 beta5 , , Async Loggers, JSP tag library JMX.

0

All Articles