I am trying to compile the following very simple Java program which will be expanded to use the log4j package:
import org.apache.log4j.Logger;
public class App {
public static void main(String[] args) {
System.out.println("Howdy");
}
}
I downloaded the binary log4j package from Apache website, untared the file, set the following exports:
$ export CLASSPATH=$CLASSPATH:/home/ahmed/temp/log4j/apache-log4j-2.11.0-bin/log4j-core-2.11.0.jar
$ export PATH=$PATH:/home/ahmed/temp/log4j/apache-log4j-2.11.0-bin
I am getting the following error when I compile App.java:
$ javac App.java
App.java:5: error: package org.apache.log4j does not exist
import org.apache.log4j.Logger;
^
1 error
I feel like I am missing something basic about java packaging/import concepts.
Thank you, Ahmed.
The Logger
interface is distributed in a different jar, you'll need to get the log4j-api-2.11.0.jar
file, and include that jar in your classpath, too.
Also, check the javadoc for log4j version 2.11 (eg. here https://logging.apache.org/log4j/2.0/log4j-api/apidocs/index.html ), Logger
is in a different package, org.apache.logging.log4j.Logger
.
(of course using an IDE+Maven or Gradle would let it much easier to sort out this type of issues).
include the jar file to your project! or set environment before starting new project! and sometimes after you set environment first on your pc, you should test in dos by cmd, some environment settings need to reboot your pc.no needed on Mac
classpath add ;.; . means you can use them in any path on your pc
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.