I am having a problem setting up the classpath
for slf4j
for compiling java files
.
I tried two ways:
1. provide the classpath
in command line
javac -cp /Users/page/.m2/repository/org/slf4j/slf4j-log4j12/1.7.5/slf4j-log4j12-1.7.5.jar src/main/java/com/scg/domain/*.java src/main/java/com/scg/util/*.java
This gave the following error:
src/main/java/com/scg/util/ListFactory.java:8: error: package org.slf4j does not exist
import org.slf4j.Logger;
^
src/main/java/com/scg/util/ListFactory.java:9: error: package org.slf4j does not exist
import org.slf4j.LoggerFactory;
...../long error message
export
the CLASSPATH
to my env
variable.export CLASSPATH=/Users/page/.m2/repository/org/slf4j/slf4j-log4j12/1.7.5/slf4j-log4j12-1.7.5.jar
This did not help either and resulted in same error, when I tried
javac src/main/java/com/scg/domain/*.java src/main/java/com/scg/util/*.java
I am trying to compile
all the java files in two packages
. but I need to have slf4j
in my classpath. but somehow I am not able to get it work.
Thanks
If you are looking for quick solution for this issue, you need to find out how log4j is present on your path. run mvn dependency:tree and figure out the maven dependency and exclude log4j with snippet below to that dependency in your pom. xml . This should resolve SLF4J: Class Path Contains Multiple SLF4J Bindings.
So essentially, SLF4j does not replace LOG4j; they work together hand in hand. It removes the dependency on LOG4j from your application and make it easy to replace it in future with more capable library without any kind of source code changes.
Unlike log4j, SLF4J (Simple Logging Facade for Java) is not an implementation of logging framework, it is an abstraction for all those logging frameworks in Java similar to log4J. Therefore, you cannot compare both.
This dependency is the api:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
You need the slf4j-api.jar in your classpath for compiling, not the slf4j-log4j12.jar.
It worked in maven because the binding-lib (slf4j-log4j12) has a dependency on the api and thus maven loads that as well, without you explicitly defining it as a dependency.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With