I'm attempting to do a very basic config that allows a customizable logger to be included in the configuration of the app. I built a skeleton of my daemon and a skeleton of the logging bean that will consume the custom logger (at the moment Log4j). At present, there is no reference to the actual logging component EXCEPT within the classpath, simply structural support framework exists. However, when I run the code, I get a logging warning:
When I remove log4j-1.2.13.jar from the classpath, I don't get the warning and it starts ok. However, as soon as I start trying to reference anything in the Log4j package (NetBeans sees the Log4j JAR and can compile the Java files) I get the following error (because it's no longer in the run-time classpath):log4j:WARN No appenders could be found for logger (org.springframework.core.CollectionFactory).
log4j:WARN Please initialize the log4j system properly.
The following is my code:Exception in thread "main" org.springframework.beans.factory.BeanDefinitionSt oreException: Error registering bean with name 'loggingBean' defined in file [/<sompath>/./conf/logging.xml]: Class that bean class [foo.bar.LoggingBean] depends on not found; nested exception is java.lang.NoClassDefFoundError: org/apache/log4j/Priority
Caused by: java.lang.NoClassDefFoundError: org/apache/log4j/Priority
Main.java
Note: this is trimmed down and doesn't include the daemonizing code
LoggingBean.javaCode:package foo.bar; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.core.io.FileSystemResource; import org.springframework.aop.ThrowsAdvice; public class Main implements ThrowsAdvice { static LoggingBean logBean; public Main() { } public static void main(String[] args) { BeanFactory factory = new XmlBeanFactory(new FileSystemResource("./conf/logging.xml")); logBean = (LoggingBean)factory.getBean("loggingBean"); } public void afterThrowing(Exception ex) throws Throwable { } public void afterThrowing(Method method, Object[] args, Object target, IllegalArgumentException ex) throws Throwable{ } }
Note: I'm not referencing any logging components yet, this is just framework
logging.xmlCode:package foo.bar; import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.InitializingBean; public class LoggingBean implements BeanNameAware, InitializingBean { private String beanName = null; private String logConfigFile; public void setBeanName(String beanName) { this.beanName = beanName; } public void afterPropertiesSet() throws Exception { if( !"".equalsIgnoreCase(logConfigFile) && null != logConfigFile ){ // Do some work } else{ throw new IllegalArgumentException("You must specify the logConfigFile property of " + LoggingBean.class); } } public void setLogConfigFile(String logConfigFile) { this.logConfigFile = logConfigFile; } }
Note: ./conf/log4j.xml exists, but again, no component has been included in LoggingBean.java to actually parse and implement the configuration it contains.
Log4j.xml (adding this just because I don't want to miss anything)Code:<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="loggingBean" class="foo.bar.LoggingBean"> <property name="logConfigFile"> <value>./conf/log4j.xml</value> </property> </bean> </beans>
My execution is:Code:<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "dtd/log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender name="R" class="org.apache.log4j.RollingFileAppender"> <param name="File" value="daemon.log" /> <param name="MaxFileSize" value="100KB" /> <param name="MaxBackupIndex" value="1" /> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%-4r [%t] (%F:%L) %-5p %c %x - %m%n" /> </layout> </appender> <root> <level value ="debug" /> <appender-ref ref="R"/> </root> </log4j:configuration>
Note: I've excluded the daemonizing bits:
Any ideas how I can allow Log4j (and, therefore, other logging components) to be injected into my app without getting this warning? Maybe I just have the setup wrong. Any guidance would be greatly appreciated. Thanks!Code:java -jar ./foobar.jar -cp ./lib/spring.jar:./lib/log4j-1.2.13.jar:./conf


Reply With Quote