Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (322)
Collections:
Other Resources:
Compiling Program with Apache Log4j
How to compile my program with Log4j 2.4.1? My program uses Log4j 2 API only and I want to know which JAR file is needed to compile it.
✍: FYIcenter.com
If your program is using Log4j 2 API,
you need to compile it
with only the Log4j 2 API JAR, like log4j-api-2.14.1.jar.
If you are using older versions of JDK, you may need to use older releases of Log4j 2 API JAR. See the JDK compatibility table below:
Release JDK Date
------- --- ----------
Apache Log4j 2.14.1 8 2021-03-12
Apache Log4j 2.12.1 7 2020-07-03
Apache Log4j 2.3 6 2020-07-03
Here is a compilation session with the HelloLog4j2.java program provided in the last tutorial. You see compilation errors, because Log4j 2 API JAR is not provided.
fyicenter> java -version
java version "15" 2020-09-15
fyicenter> javac HelloLog4j2.java
HelloLog4j2.java:4: error: cannot find symbol
private static final Logger logger = LogManager.getLogger("fyiLogger");
^
symbol: class Logger
location: class HelloLog4j2
HelloLog4j2.java:2: error: package org.apache.logging.log4j does not exist
import org.apache.logging.log4j.*;
^
HelloLog4j2.java:4: error: cannot find symbol
private static final Logger logger = LogManager.getLogger("fyiLogger");
^
symbol: variable LogManager
location: class HelloLog4j2
3 errors
Compile it again with Log4j 2 API JAR provided. You see bytecode file generated.
fyicenter> javac -cp log4j-api-2.14.1.jar HelloLog4j2.java fyicenter> dir 1584 Jul 4 14:19 HelloLog4j2.class
The above session shows that:
⇒ Running Program with Apache Log4j
⇐ Hello Program with Apache Log4j
2015-11-18, ∼3913🔥, 0💬
Popular Posts:
JRE 8 rt.jar is the JAR file for JRE 8 RT (Runtime) libraries. JRE (Java Runtime) 8 is the runtime e...
What Is commons-lang3-3.1.jar? commons-lang3-3.1.jar is the JAR file for Apache Commons Lang 3.1, wh...
What Is poi-5.2.3.jar? poi-5.2.3.jar is one of the JAR files for Apache POI 5.2.3, which provides an...
JDK 17 jdk.hotspot.agent.jmod is the JMOD file for JDK 17 Hotspot Agent module. JDK 17 Hotspot Agent...
JDK 11 jdk.jshell.jmod is the JMOD file for JDK 11 JShell tool, which can be invoked by the "jshell"...