问题描述
测试代码Hello.java:importorg.apache.log4j.Logger;importorg.apache.log4j.PropertyConfigurator;publicclassHello{staticLoggerlogger=Logger.getLogger(Hello.class);publicstaticvoidmain(Stringargs[]){PropertyConfigurator.configure(args[0]);logger.debug("Helloworld!");logger.info("Welcomeyou!");}}log4j配置文件hello.lcf:log4j.rootLogger=DEBUG,Allog4j.appender.Al=org.apache.log4j.ConsoleAppenderlog4j.appender.Al.layout=org.apache.log4j.PatternLayoutlog4j.appender.Al.layout.ConversionPattern=%r[%t]%p%c%x-%m%n我将编译后的Hello.class和hello.lcf放到同一目录下,在命令行下输入:javaHellohello.lcf出现异常如下:Exceptioninthread"main"java.lang.NoClassDefFoundError:HelloCausedby:java.lang.ClassNotFoundException:Helloatjava.net.URLClassLoader$1.run(URLClassLoader.java:200)atjava.security.AccessController.doPrivileged(NativeMethod)atjava.net.URLClassLoader.findClass(URLClassLoader.java:188)atjava.lang.ClassLoader.loadClass(ClassLoader.java:307)atsun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)atjava.lang.ClassLoader.loadClass(ClassLoader.java:252)atjava.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)Couldnotfindthemainclass:Hello.Programwillexit.在eclipse下运行则出现下面的异常:log4j:ERRORCouldnotreadconfigurationfile[hello.lcf].java.io.FileNotFoundException:hello.lcf(系统找不到指定的文件。)atjava.io.FileInputStream.open(NativeMethod)atjava.io.FileInputStream.<init>(FileInputStream.java:106)atjava.io.FileInputStream.<init>(FileInputStream.java:66)atorg.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:316)atorg.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:342)atHello.main(Hello.java:8)log4j:ERRORIgnoringconfigurationfile[hello.lcf].log4j:WARNNoappenderscouldbefoundforlogger(Hello).log4j:WARNPleaseinitializethelog4jsystemproperly.请各位朋友看看是怎么回事
解决方案
解决方案二:
不好意思哈,写错了,我没有分