2012-07-30 65 views
2

我從Maven的回購使用Log4j-1.2.17包。 我嘗試做的包代碼(我的包調用log4j的-1.2.17包)類加載問題與OSGi的

PropertyConfigurator.configure(props()); 
private static Properties props() { 
    Properties props = new Properties(); 
    props.put("log4j.rootLogger", "INFO, R"); 
    props.put("log4j.appender.R", 
      "org.apache.log4j.DailyRollingFileAppender"); 
    props.put("log4j.appender.R.File", "logs/IhtikaClient.log"); 
    props.put("log4j.appender.R.Append", "true"); 
    props.put("log4j.appender.R.Threshold", "INFO"); 
    props.put("log4j.appender.R.DatePattern", "'.'yyyy-MM-dd"); 
    props.put("log4j.appender.R.layout", "org.apache.log4j.PatternLayout"); 
    props.put("log4j.appender.R.layout.ConversionPattern", 
      //"%d{HH:mm:ss,SSS} %c - %m%n"); 
      //"[%5p] %d{yyyy-MM-dd mm:ss} (%F:%M:%L)%n%m%n%n"); 
      "[%5p] %d{yyyy-MM-dd mm:ss} %c (%F:%M:%L)%n%m%n"); 
    return props; 
} 

但我有錯誤

log4j:ERROR A "org.apache.log4j.DailyRollingFileAppender" object is not assignable to a "org.apache.log4j.Appender" variable. log4j:ERROR The class "org.apache.log4j.Appender" was loaded by log4j:ERROR [[email protected]] whereas object of type log4j:ERROR "org.apache.log4j.DailyRollingFileAppender" was loaded by [[email protected]]. log4j:ERROR Could not instantiate appender named "R". log4j:ERROR A "org.apache.log4j.DailyRollingFileAppender" object is not assignable to a "org.apache.log4j.Appender" variable. log4j:ERROR The class "org.apache.log4j.Appender" was loaded by log4j:ERROR [[email protected]] whereas object of type log4j:ERROR "org.apache.log4j.DailyRollingFileAppender" was loaded by [[email protected]]. log4j:ERROR Could not instantiate appender named "R".

捆綁已序列

載入中
.getBundleContext().installBundle("......../log4j-1.2.17.jar") 
.getBundleContext().installBundle("......../I_MainForm-1.0-SNAPSHOT.jar") 

如何解決此錯誤? 請抱歉,我的英語。 最好的問候,亞瑟。

回答

4

由於您的Log4j類似乎已被加載了一個sun.misc類加載器,我認爲有東西從外部OSGi提供log4j類。有Log4J的條目解釋爲什麼它不能加載的Log4J類,這意味着Log4J的一些版本已經存在

是否使用菲利克斯的定製版本?如果是這樣,你能找到類似org.osgi.framework.system.packages=...條目或org.osgi.framework.system.packages.extra=...條目的配置文件嗎?

如果你只是刪除Log4j的包,會發生什麼?它仍然可以找到Log4j類嗎?

問候,弗蘭克

+0

你好。是的,這是我的錯誤 - 主應用程序(Loader應用程序)具有log4j lib(不是捆綁包)。在我刪除這個lib之後,execption現在不顯示。對不起我的英文。謝謝。 – 2012-07-30 11:13:04

+0

@ user913766:請使用左側的勾號接受此答案。 – 2012-07-30 17:41:20

7

基本上沒有「泄漏」你的類到使用org.osgi.framework.system.packagesorg.osgi.framework.system.packages.extra,除非你真的需要在你的代碼,而不是固定的一些其他問題的框架。顯然,這是log4j問題。

你可以通過設置系統屬性修正:

-Dlog4j.ignoreTCL=true