我從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")
如何解決此錯誤? 請抱歉,我的英語。 最好的問候,亞瑟。
你好。是的,這是我的錯誤 - 主應用程序(Loader應用程序)具有log4j lib(不是捆綁包)。在我刪除這個lib之後,execption現在不顯示。對不起我的英文。謝謝。 – 2012-07-30 11:13:04
@ user913766:請使用左側的勾號接受此答案。 – 2012-07-30 17:41:20