2017-01-10 80 views
0

我是新來的maven。我已經下載並解壓縮它。另外我已經將bin目錄添加到系統路徑中。所以, 'MVN -v' 工作得很好,看到'mvn -v'work,but'mvn'或'mvn compile'拋出異常

```

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" 

```

然而,當我嘗試使用 'MVN編譯' 來編譯Java項目,它拋出一個例外。該項目由一個pom.xml文件和兩個來自教程https://spring.io/guides/gs/maven/#initial的java文件組成。 異常說,

```

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 

```

心中已經幾天谷歌的解決方案,但一無所獲。請幫我學習我的maven。感謝sooooooooooooooo多

+0

退房這裏http://stackoverflow.com/questions/3737992/noclassdeffounderror-org-slf4j-impl-staticloggerbinder – Imran

+0

我假設你已經在你的環境中不同的Maven的版本設置M2_HOME ...是的Maven您在PATH中定義的版本與M2_HOME中定義的版本相同嗎?此外爲什麼不使用最新版本3.3.9? – khmarbaise

回答

0

我認爲你需要添加在你的POM

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

試試吧,讓我們知道下面的依賴,如果它的工作

+1

我已經得到了解決方案。我重新安裝了java並重新配置了環境變量,異常消失了...無論如何,謝謝! – user3674943

0

不應該用Google搜索。應該剛剛訪問了例外情況中提到的鏈接(http://www.slf4j.org/codes.html#StaticLoggerBinder)。

這是它說 -

這種情況發生時沒有合適的SLF4J綁定可以在類路徑上找到。 在類路徑中放置slf4j-nop.jar slf4j-simple.jar,slf4j-log4j12.jar,slf4j-jdk14.jar或logback-classic.jar中的一個(並且只有一個)應該可以解決問題。

通常Maven的lib文件夾中自帶slf4j-simple.jar,嘗試補充說,讓我們知道結果。

它還說 -

如果您負責打包應用程序並不在乎 有關日誌記錄,那麼你的 應用的類路徑上放置slf4j-nop.jar將擺脫這一警告的信息。

+0

我已經得到了解決方案。我重新安裝了java並重新配置了環境變量,異常消失了......感謝您的幫助。 – user3674943

+0

很酷。祝你下一步好運。 –