为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
setting classpath for slf4j for java compiling
提问by eagertoLearn
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
我有一个问题,设立classpath
了slf4j
为compiling java files
。我尝试了两种方法: 1. 提供classpath
incommand 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
theCLASSPATH
to myenv
variable.
- 我试图
export
将CLASSPATH
我的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 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
我正在尝试将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 也会加载它,而无需您明确将其定义为依赖项。