java.lang.NoClassDefFoundError: Lorg/slf4j/Logger;

如果你出现类似如下错误

1. Install tomcat7 in my home directory and set up `CATALINA_HOME`
    environment variable in `.bashrc`
 2. Install oracle-java and setup JAVA_HOME in `.bashrc`
 3. Install Netbeans 7 and import the project in it.
 4. Since, the Netbeans came with `glassfish` as default server, I added
    a tomcat as the server with proper configuration.
 5. I try running the application (through Netbeans), and I receive the following error:

Jun 04, 2013 2:39:58 AM org.apache.catalina.core.AprLifecycleListener init
  2 INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/        lib:/usr/lib
  3 Jun 04, 2013 2:39:59 AM org.apache.coyote.AbstractProtocol init
  4 INFO: Initializing ProtocolHandler ["http-bio-8080"]
  5 Jun 04, 2013 2:39:59 AM org.apache.coyote.AbstractProtocol init
  6 INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
  7 Jun 04, 2013 2:39:59 AM org.apache.catalina.startup.Catalina load
  8 INFO: Initialization processed in 1100 ms
  9 Jun 04, 2013 2:39:59 AM org.apache.catalina.core.StandardService startInternal
 10 INFO: Starting service Catalina
 11 Jun 04, 2013 2:39:59 AM org.apache.catalina.core.StandardEngine startInternal
 12 INFO: Starting Servlet Engine: Apache Tomcat/7.0.40
 13 Jun 04, 2013 2:39:59 AM org.apache.catalina.startup.HostConfig deployDescriptor
 14 INFO: Deploying configuration descriptor /home/frrole/apache-tomcat-7.0.40/conf/Catalina/localhost/ws.xml
 15 Jun 04, 2013 2:39:59 AM org.apache.catalina.startup.HostConfig deployDescriptor
 16 WARNING: A docBase /home/frrole/apache-tomcat-7.0.40/webapps/projectfrrole/target/ws inside the host appBase has been specified, and will be ignored
 17 Jun 04, 2013 2:40:00 AM org.apache.catalina.core.ContainerBase addChildInternal
 18 SEVERE: ContainerBase.addChild: start:
 19 org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/ws]]
 20     at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
 21     at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
 22     at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
 23     at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
 24     at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:657)
 25     at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1636)
 26     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
 27     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
 28     at java.util.concurrent.FutureTask.run(FutureTask.java:166)
 29     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
 30     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
 31     at java.lang.Thread.run(Thread.java:722)
 32 Caused by: java.lang.NoClassDefFoundError: Lorg/slf4j/Logger;
 33     at java.lang.Class.getDeclaredFields0(Native Method)
 34     at java.lang.Class.privateGetDeclaredFields(Class.java:2317)
 35     at java.lang.Class.getDeclaredFields(Class.java:1762)
 36     at org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:106)
 37     at org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(WebAnnotationSet.java:261)
 38     at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:140)
 39     at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:67)
 40     at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:405)
 41     at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:881)
 42     at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:369)
 43     at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
 44     at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
 45     at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5269)
 46     at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
 47     ... 11 more
 48 Caused by: java.lang.ClassNotFoundException: org.slf4j.Logger
 49     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)

那么原因暂时有两种:

1、你的项目没有依赖slf4j-log4j12.jar

2、如果你依赖了slf4j-log4j12.jar,那么请检测是否也依赖了slf4j-api.jar,他们会冲突,把slf4j-api.jar干掉吧

文章来自:http://www.cnblogs.com/langtianya/p/5838493.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3