为java编译设置slf4j的类路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21738544/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 10:25:31  来源:igfitidea点击:

setting classpath for slf4j for java compiling

javaclasspathjavacslf4j

提问by eagertoLearn

I am having a problem setting up the classpathfor slf4jfor compiling java files. I tried two ways: 1. provide the classpathin command line

我有一个问题,设立classpathslf4jcompiling java files。我尝试了两种方法: 1. 提供classpathincommand 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
  1. I tried to exportthe CLASSPATHto my envvariable.
  1. 我试图exportCLASSPATH我的env变量。

export CLASSPATH=/Users/page/.m2/repository/org/slf4j/slf4j-log4j12/1.7.5/slf4j-log4j12-1.7.5.jar

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 compileall the java files in two packages. but I need to have slf4jin my classpath. but somehow I am not able to get it work. Thanks

我正在尝试将compile所有 java 文件分成两个packages. 但我需要slf4j在我的类路径中有. but somehow I am not able to get it work. 谢谢

采纳答案by sheltem

This dependency is the api:

这个依赖是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.

您需要在类路径中使用 slf4j-api.jar 进行编译,而不是 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.

它在 maven 中工作,因为 binding-lib (slf4j-log4j12) 依赖于 api,因此 maven 也会加载它,而无需您明确将其定义为依赖项。