我以前只和log4j
一起工作過。現在我正在探索一個新項目並注意到它使用了slf4j 1.7.2
。我知道它只是一個API規範,它爲與之相符的各種實現提供了簡化的接口(AKA外觀),如java.util.logging, log4j and logback。但是,我注意到,在API網站的列表中沒有提到commons-logging
,但是,它的jar包含在這個應用程序的類路徑中。當我刪除它從classpath檢查它是否是使用implemetation,我證實,它的確是:slf4j默認使用commons-logging實現嗎?
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
是共享記錄確實SLF4J默認的實現?因爲他們的文檔說:
如果在類路徑上找不到綁定,則SLF4J將默認爲無操作實現。
在上述鏈接的頁面上。即使我在類路徑中有slf4j-nop-1.7.2.jar
,我猜測上面提到的默認實現是,但如果commons不在類路徑中,我仍然會得到org/apache/commons/logging/LogFactory
的異常,所以我很困惑。
澄清將不勝感激。
我的猜測是,你有一些其他的依賴項正在拉動commons-logging。如果你正在使用maven或者類似的構建工具,你應該能夠可視化你的依賴關係樹並查看包括commons-logging在內的內容。 – 2013-02-21 23:21:31
其實,我使用Ant – amphibient 2013-02-21 23:22:46