0

I'm new to maven. I had downloaded and unpacked it. Also I had added bin directory into system path. So 'mvn -v' work well, see

```

Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-15T01:29:23+08:00)
Maven home: D:\apache-maven-3.2.5\bin\..  
Java version: 1.8.0_101, vendor: Oracle Corporation  
Java home: D:\Program Files\Java\jdk1.8.0_101\jre  
Default locale: zh_CN, platform encoding: GBK  
OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"  

```

However, when I tried to compile a java project using 'mvn compile', it threw an exception. the project consists of a pom.xml file and two java file from the tutorial https://spring.io/guides/gs/maven/#initial. the exception says,

```

E:\Code\java\test_maven>mvn compile   
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder"  
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.  
constituent[0]: file:/D:/apache-maven-3.2.5/bin/../lib/aether-api-1.0.0.v20140518.jar  
constituent[1]: file:/D:/apache-maven-3.2.5/bin/../lib/aether-connector-basic-1.0.0.v20140518.jar  
constituent[2]: file:/D:/apache-maven-3.2.5/bin/../lib/aether-impl-1.0.0.v20140518.jar  
constituent[3]: file:/D:/apache-maven-3.2.5/bin/../lib/aether-spi-1.0.0.v20140518.jar  
constituent[4]: file:/D:/apache-maven-3.2.5/bin/../lib/aether-transport-wagon-1.0.0.v20140518.jar  
constituent[5]: file:/D:/apache-maven-3.2.5/bin/../lib/aether-util-1.0.0.v20140518.jar  
constituent[6]: file:/D:/apache-maven-3.2.5/bin/../lib/aopalliance-1.0.jar  
constituent[7]: file:/D:/apache-maven-3.2.5/bin/../lib/cdi-api-1.0.jar  
constituent[8]: file:/D:/apache-maven-3.2.5/bin/../lib/commons-cli-1.2.jar  
constituent[9]: file:/D:/apache-maven-3.2.5/bin/../lib/commons-io-2.2.jar  
constituent[10]: file:/D:/apache-maven-3.2.5/bin/../lib/commons-lang-2.6.jar  
constituent[11]: file:/D:/apache-maven-3.2.5/bin/../lib/guava-18.0.jar  
constituent[12]: file:/D:/apache-maven-3.2.5/bin/../lib/javax.inject-1.jar  
constituent[13]: file:/D:/apache-maven-3.2.5/bin/../lib/jsoup-1.7.2.jar  
constituent[14]: file:/D:/apache-maven-3.2.5/bin/../lib/jsr250-api-1.0.jar  
constituent[15]: file:/D:/apache-maven-3.2.5/bin/../lib/maven-aether-provider-3.2.5.jar  
constituent[16]: file:/D:/apache-maven-3.2.5/bin/../lib/maven-artifact-3.2.5.jar  
constituent[17]: file:/D:/apache-maven-3.2.5/bin/../lib/maven-compat-3.2.5.jar  
constituent[18]: file:/D:/apache-maven-3.2.5/bin/../lib/maven-core-3.2.5.jar  
constituent[19]: file:/D:/apache-maven-3.2.5/bin/../lib/maven-embedder-3.2.5.jar  
constituent[20]: file:/D:/apache-maven-3.2.5/bin/../lib/maven-model-3.2.5.jar  
constituent[21]: file:/D:/apache-maven-3.2.5/bin/../lib/maven-model-builder-3.2.5.jar  
constituent[22]: file:/D:/apache-maven-3.2.5/bin/../lib/maven-plugin-api-3.2.5.jar  
constituent[23]: file:/D:/apache-maven-3.2.5/bin/../lib/maven-repository-metadata-3.2.5.jar  
constituent[24]: file:/D:/apache-maven-3.2.5/bin/../lib/maven-settings-3.2.5.jar  
constituent[25]: file:/D:/apache-maven-3.2.5/bin/../lib/maven-settings-builder-3.2.5.jar  
constituent[26]: file:/D:/apache-maven-3.2.5/bin/../lib/org.eclipse.sisu.inject-0.3.0.M1.jar  
constituent[27]: file:/D:/apache-maven-3.2.5/bin/../lib/org.eclipse.sisu.plexus-0.3.0.M1.jar  
constituent[28]: file:/D:/apache-maven-3.2.5/bin/../lib/plexus-cipher-1.7.jar  
constituent[29]: file:/D:/apache-maven-3.2.5/bin/../lib/plexus-component-annotations-1.5.5.jar  
constituent[30]: file:/D:/apache-maven-3.2.5/bin/../lib/plexus-interpolation-1.21.jar  
constituent[31]: file:/D:/apache-maven-3.2.5/bin/../lib/plexus-sec-dispatcher-1.3.jar  
constituent[32]: file:/D:/apache-maven-3.2.5/bin/../lib/plexus-utils-3.0.20.jar  
constituent[33]: file:/D:/apache-maven-3.2.5/bin/../lib/sisu-guice-3.2.3-no_aop.jar  
constituent[34]: file:/D:/apache-maven-3.2.5/bin/../lib/slf4j-api-1.7.5.jar  
constituent[35]: file:/D:/apache-maven-3.2.5/bin/../lib/slf4j-simple-1.7.5.jar  
constituent[36]: file:/D:/apache-maven-3.2.5/bin/../lib/wagon-file-2.8.jar  
constituent[37]: file:/D:/apache-maven-3.2.5/bin/../lib/wagon-http-2.8-shaded.jar  
constituent[38]: file:/D:/apache-maven-3.2.5/bin/../lib/wagon-http-shared-2.8.jar  
constituent[39]: file:/D:/apache-maven-3.2.5/bin/../lib/wagon-provider-api-2.8.jar  
constituent[40]: file:/D:/apache-maven-3.2.5/bin/../conf/logging/  
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder  
        at org.slf4j.LoggerFactory.getSingleton(LoggerFactory.java:230)  
        at org.slf4j.LoggerFactory.bind(LoggerFactory.java:121)  
        at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:112)  
        at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:275)  
        at org.apache.maven.cli.MavenCli.logging(MavenCli.java:311)  
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:207)  
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:160)  
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)  
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)  
        at java.lang.reflect.Method.invoke(Method.java:498)  
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)  
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)  
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)  
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)  
Caused by: java.lang.ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder  
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)  
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)  
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)  
         15 more

```

I'v google days for the solution but find nothing. Please help me with my maven learning. Thanks sooooooooooooooo much

  • check out here http://stackoverflow.com/questions/3737992/noclassdeffounderror-org-slf4j-impl-staticloggerbinder – Imran Jan 10 '17 at 07:43
  • I assume you have set M2_HOME in your environment to a different Maven version...Is the Maven version you have defined in your PATH the same as defined in M2_HOME? Furthermore why not using the most recent version 3.3.9? – khmarbaise Jan 10 '17 at 08:18

2 Answers2

0

I think that you need to add the following dependency in your pom

<dependency>    
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>  
     <version>1.5.6</version>
 </dependency>

Try it and let us know if it worked

SCouto
  • 7,808
  • 5
  • 32
  • 49
  • 1
    I have got the solution. I reinstalled java and reconfigurated the environment variables, the exception disappeared...Thank you anyway! – user3674943 Jan 10 '17 at 08:00
0

Shouldn't have Googled. Should have just visited the link mentioned in the exception (http://www.slf4j.org/codes.html#StaticLoggerBinder).

This is what it says -

This happens when no appropriate SLF4J binding could be found on the class path. Placing one (and only one) of slf4j-nop.jar slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem.

Usually Maven's lib folder comes with slf4j-simple.jar, try adding that and let us know the result.

It further says -

If you are responsible for packaging an application and do not care about logging, then placing slf4j-nop.jar on the class path of your application will get rid of this warning message.

Pavan Kumar
  • 4,182
  • 1
  • 30
  • 45