setting classpath for slf4j for java compiling

classpath, java, javac, slf4j

Solution

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.

Problem

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 ``` - I tried to `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

Original source