SLF4J:线程“main”java.lang.NoSuchMethodError中的异常

时间:2014-12-26 08:39:15

标签: java maven hadoop hbase slf4j

我正在尝试使用HBase处理一个介绍项目,但我遇到了SLF4J的错误。我甚至不在我的项目中使用SLF4J,但我无法理解如何解决这个问题。我在这里经历了一些其他帖子,发现应该执行从其他导入中排除SLF4J来解决此问题,但看起来我仍然遇到此问题。我正在添加错误,pom.xml,依赖关系树和我正在运行的java命令。

错误

log4j:WARN No appenders could be found for logger (org.apache.hadoop.util.Shell).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
SLF4J: slf4j-api 1.6.x (or later) is incompatible with this binding.
SLF4J: Your binding is version 1.5.5 or earlier.
SLF4J: Upgrade your binding to version 1.6.x.
Exception in thread "main" java.lang.NoSuchMethodError: org.slf4j.impl.StaticLoggerBinder.getSingleton()Lorg/slf4j/impl/StaticLoggerBinder;
    at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128)
    at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:107)
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:295)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:269)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:281)
    at org.apache.zookeeper.ZooKeeper.<clinit>(ZooKeeper.java:94)
    at org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper.<init>(RecoverableZooKeeper.java:98)
    at org.apache.hadoop.hbase.zookeeper.ZKUtil.connect(ZKUtil.java:127)
    at org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher.<init>(ZooKeeperWatcher.java:153)
    at org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher.<init>(ZooKeeperWatcher.java:127)
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getZooKeeperWatcher(HConnectionManager.java:1505)
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.ensureZookeeperTrackers(HConnectionManager.java:713)
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegion(HConnectionManager.java:983)
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegion(HConnectionManager.java:958)
    at org.apache.hadoop.hbase.client.HTable.finishSetup(HTable.java:251)
    at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:243)
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getTable(HConnectionManager.java:668)
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getTable(HConnectionManager.java:655)
    at com.hbase_intro.HBaseIntro.AccessObject.addUser(AccessObject.java:103)
    at com.hbase_intro.HBaseIntro.HelloWorld.main(HelloWorld.java:32)

的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.hbase-intro</groupId>
  <artifactId>HBaseIntro</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>HBaseIntro</name>
  <url>http://maven.apache.org</url>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
      <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </exclusion>
    </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-common</artifactId>
        <version>2.4.0</version>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.hbase</groupId>
        <artifactId>hbase</artifactId>
        <version>0.94.18</version>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.5</version>
    </dependency>
  </dependencies>
  <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.5.3</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>assemble-all</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>com.hbase_intro.HBaseIntro.HelloWorld</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
  </build>
</project>

依赖树(我生成了带有详细标记的依赖树,看起来正在编译SLF4J 1.4.3

+- junit:junit:jar:3.8.1:test
+- org.apache.hadoop:hadoop-common:jar:2.4.0:compile
|  +- org.apache.hadoop:hadoop-annotations:jar:2.4.0:compile
|  |  \- jdk.tools:jdk.tools:jar:1.7:system
|  +- com.google.guava:guava:jar:11.0.2:compile
|  |  \- (com.google.code.findbugs:jsr305:jar:1.3.9:compile - omitted for duplicate)
|  +- commons-cli:commons-cli:jar:1.2:compile
|  +- org.apache.commons:commons-math3:jar:3.1.1:compile
|  +- xmlenc:xmlenc:jar:0.52:compile
|  +- commons-httpclient:commons-httpclient:jar:3.1:compile
|  |  +- (commons-logging:commons-logging:jar:1.0.4:compile - omitted for conflict with 1.1.3)
|  |  \- (commons-codec:commons-codec:jar:1.2:compile - omitted for conflict with 1.4)
|  +- commons-codec:commons-codec:jar:1.4:compile
|  +- commons-io:commons-io:jar:2.4:compile
|  +- commons-net:commons-net:jar:3.1:compile
|  +- commons-collections:commons-collections:jar:3.2.1:compile
|  +- javax.servlet:servlet-api:jar:2.5:compile
|  +- org.mortbay.jetty:jetty:jar:6.1.26:compile
|  |  \- (org.mortbay.jetty:jetty-util:jar:6.1.26:compile - omitted for duplicate)
|  +- org.mortbay.jetty:jetty-util:jar:6.1.26:compile
|  +- com.sun.jersey:jersey-core:jar:1.9:compile
|  +- com.sun.jersey:jersey-json:jar:1.9:compile
|  |  +- org.codehaus.jettison:jettison:jar:1.1:compile
|  |  +- com.sun.xml.bind:jaxb-impl:jar:2.2.3-1:compile
|  |  |  \- (javax.xml.bind:jaxb-api:jar:2.2.2:compile - omitted for conflict with 2.1)
|  |  +- (org.codehaus.jackson:jackson-core-asl:jar:1.8.3:compile - omitted for conflict with 1.8.8)
|  |  +- (org.codehaus.jackson:jackson-mapper-asl:jar:1.8.3:compile - omitted for conflict with 1.8.8)
|  |  +- (org.codehaus.jackson:jackson-jaxrs:jar:1.8.3:compile - omitted for conflict with 1.8.8)
|  |  +- (org.codehaus.jackson:jackson-xc:jar:1.8.3:compile - omitted for conflict with 1.8.8)
|  |  \- (com.sun.jersey:jersey-core:jar:1.9:compile - omitted for duplicate)
|  +- com.sun.jersey:jersey-server:jar:1.9:compile
|  |  +- asm:asm:jar:3.1:compile
|  |  \- (com.sun.jersey:jersey-core:jar:1.9:compile - omitted for duplicate)
|  +- tomcat:jasper-compiler:jar:5.5.23:runtime
|  +- tomcat:jasper-runtime:jar:5.5.23:runtime
|  |  +- (javax.servlet:servlet-api:jar:2.4:runtime - omitted for conflict with 2.5)
|  |  \- (commons-el:commons-el:jar:1.0:runtime - omitted for duplicate)
|  +- javax.servlet.jsp:jsp-api:jar:2.1:runtime
|  +- commons-el:commons-el:jar:1.0:runtime
|  |  \- (commons-logging:commons-logging:jar:1.0.3:runtime - omitted for conflict with 1.0.4)
|  +- commons-logging:commons-logging:jar:1.1.3:compile
|  +- log4j:log4j:jar:1.2.17:compile
|  +- net.java.dev.jets3t:jets3t:jar:0.9.0:compile
|  |  +- (commons-codec:commons-codec:jar:1.4:compile - omitted for duplicate)
|  |  +- (commons-logging:commons-logging:jar:1.1.1:compile - omitted for conflict with 1.1.3)
|  |  +- org.apache.httpcomponents:httpclient:jar:4.1.2:compile
|  |  |  \- (org.apache.httpcomponents:httpcore:jar:4.1.2:compile - omitted for duplicate)
|  |  +- org.apache.httpcomponents:httpcore:jar:4.1.2:compile
|  |  \- com.jamesmurty.utils:java-xmlbuilder:jar:0.4:compile
|  +- commons-lang:commons-lang:jar:2.6:compile
|  +- commons-configuration:commons-configuration:jar:1.6:compile
|  |  +- (commons-collections:commons-collections:jar:3.2.1:compile - omitted for duplicate)
|  |  +- (commons-lang:commons-lang:jar:2.4:compile - omitted for conflict with 2.6)
|  |  +- (commons-logging:commons-logging:jar:1.1.1:compile - omitted for conflict with 1.1.3)
|  |  +- commons-digester:commons-digester:jar:1.8:compile
|  |  |  +- commons-beanutils:commons-beanutils:jar:1.7.0:compile
|  |  |  |  \- (commons-logging:commons-logging:jar:1.0.3:compile - omitted for conflict with 1.1.3)
|  |  |  \- (commons-logging:commons-logging:jar:1.1:compile - omitted for conflict with 1.1.3)
|  |  \- commons-beanutils:commons-beanutils-core:jar:1.8.0:compile
|  |     \- (commons-logging:commons-logging:jar:1.1.1:compile - omitted for conflict with 1.1.3)
|  +- (org.slf4j:slf4j-log4j12:jar:1.7.5:compile - scope updated from runtime; omitted for duplicate)
|  +- org.codehaus.jackson:jackson-core-asl:jar:1.8.8:compile
|  +- org.codehaus.jackson:jackson-mapper-asl:jar:1.8.8:compile
|  |  \- (org.codehaus.jackson:jackson-core-asl:jar:1.8.8:compile - omitted for duplicate)
|  +- org.apache.avro:avro:jar:1.7.4:compile
|  |  +- (org.codehaus.jackson:jackson-core-asl:jar:1.8.8:compile - omitted for duplicate)
|  |  +- (org.codehaus.jackson:jackson-mapper-asl:jar:1.8.8:compile - omitted for duplicate)
|  |  +- com.thoughtworks.paranamer:paranamer:jar:2.3:compile
|  |  +- org.xerial.snappy:snappy-java:jar:1.0.4.1:compile
|  |  \- (org.apache.commons:commons-compress:jar:1.4.1:compile - omitted for duplicate)
|  +- com.google.protobuf:protobuf-java:jar:2.5.0:compile
|  +- org.apache.hadoop:hadoop-auth:jar:2.4.0:compile
|  |  +- (commons-codec:commons-codec:jar:1.4:compile - omitted for duplicate)
|  |  +- (log4j:log4j:jar:1.2.17:runtime - omitted for duplicate)
|  |  +- (org.slf4j:slf4j-log4j12:jar:1.7.5:runtime - omitted for duplicate)
|  |  \- (org.apache.httpcomponents:httpclient:jar:4.2.5:compile - omitted for conflict with 4.1.2)
|  +- com.jcraft:jsch:jar:0.1.42:compile
|  +- com.google.code.findbugs:jsr305:jar:1.3.9:compile
|  +- org.apache.zookeeper:zookeeper:jar:3.4.5:compile
|  |  +- (org.slf4j:slf4j-log4j12:jar:1.7.5:compile - omitted for conflict with 1.4.3)
|  |  \- (log4j:log4j:jar:1.2.15:compile - omitted for conflict with 1.2.17)
|  \- org.apache.commons:commons-compress:jar:1.4.1:compile
|     \- org.tukaani:xz:jar:1.0:compile
+- org.apache.hbase:hbase:jar:0.94.18:compile
|  +- com.yammer.metrics:metrics-core:jar:2.1.2:compile
|  +- (com.google.guava:guava:jar:11.0.2:compile - omitted for duplicate)
|  +- (commons-cli:commons-cli:jar:1.2:compile - omitted for duplicate)
|  +- (commons-configuration:commons-configuration:jar:1.6:compile - omitted for duplicate)
|  +- com.github.stephenc.high-scale-lib:high-scale-lib:jar:1.1.1:compile
|  +- (commons-codec:commons-codec:jar:1.4:compile - omitted for duplicate)
|  +- (commons-httpclient:commons-httpclient:jar:3.1:compile - omitted for duplicate)
|  +- (commons-io:commons-io:jar:2.1:compile - omitted for conflict with 2.4)
|  +- (commons-lang:commons-lang:jar:2.5:compile - omitted for conflict with 2.6)
|  +- (commons-logging:commons-logging:jar:1.1.1:compile - omitted for conflict with 1.1.3)
|  +- (log4j:log4j:jar:1.2.16:compile - omitted for conflict with 1.2.17)
|  +- (org.apache.avro:avro:jar:1.5.3:compile - omitted for conflict with 1.7.4)
|  +- org.apache.avro:avro-ipc:jar:1.5.3:compile
|  |  +- (org.apache.avro:avro:jar:1.5.3:compile - omitted for conflict with 1.7.4)
|  |  +- (org.mortbay.jetty:jetty:jar:6.1.26:compile - omitted for duplicate)
|  |  +- org.jboss.netty:netty:jar:3.2.4.Final:compile
|  |  \- org.apache.velocity:velocity:jar:1.7:compile
|  |     +- (commons-collections:commons-collections:jar:3.2.1:compile - omitted for duplicate)
|  |     \- (commons-lang:commons-lang:jar:2.4:compile - omitted for conflict with 2.6)
|  +- (org.apache.zookeeper:zookeeper:jar:3.4.5:compile - omitted for duplicate)
|  +- org.apache.thrift:libthrift:jar:0.8.0:compile
|  |  +- (commons-lang:commons-lang:jar:2.5:compile - omitted for conflict with 2.6)
|  |  +- (org.apache.httpcomponents:httpclient:jar:4.1.2:compile - omitted for duplicate)
|  |  \- (org.apache.httpcomponents:httpcore:jar:4.1.3:compile - omitted for conflict with 4.1.2)
|  +- org.jruby:jruby-complete:jar:1.6.5:compile
|  +- (org.mortbay.jetty:jetty:jar:6.1.26:compile - omitted for duplicate)
|  +- (org.mortbay.jetty:jetty-util:jar:6.1.26:compile - omitted for duplicate)
|  +- org.mortbay.jetty:jsp-2.1:jar:6.1.14:compile
|  |  +- org.eclipse.jdt:core:jar:3.1.1:compile
|  |  \- (org.mortbay.jetty:jsp-api-2.1:jar:6.1.14:compile - omitted for duplicate)
|  +- org.mortbay.jetty:jsp-api-2.1:jar:6.1.14:compile
|  |  \- (org.mortbay.jetty:servlet-api-2.5:jar:6.1.14:compile - omitted for duplicate)
|  +- org.mortbay.jetty:servlet-api-2.5:jar:6.1.14:compile
|  +- (org.codehaus.jackson:jackson-core-asl:jar:1.8.8:compile - omitted for duplicate)
|  +- (org.codehaus.jackson:jackson-mapper-asl:jar:1.8.8:compile - omitted for duplicate)
|  +- org.codehaus.jackson:jackson-jaxrs:jar:1.8.8:compile
|  |  +- (org.codehaus.jackson:jackson-core-asl:jar:1.8.8:compile - omitted for duplicate)
|  |  \- (org.codehaus.jackson:jackson-mapper-asl:jar:1.8.8:compile - omitted for duplicate)
|  +- org.codehaus.jackson:jackson-xc:jar:1.8.8:compile
|  |  +- (org.codehaus.jackson:jackson-core-asl:jar:1.8.8:compile - omitted for duplicate)
|  |  \- (org.codehaus.jackson:jackson-mapper-asl:jar:1.8.8:compile - omitted for duplicate)
|  +- org.slf4j:slf4j-log4j12:jar:1.4.3:compile
|  |  \- (log4j:log4j:jar:1.2.13:compile - omitted for conflict with 1.2.17)
|  +- (tomcat:jasper-compiler:jar:5.5.23:runtime - omitted for duplicate)
|  +- (tomcat:jasper-runtime:jar:5.5.23:runtime - omitted for duplicate)
|  +- org.jamon:jamon-runtime:jar:2.3.1:compile
|  +- (com.google.protobuf:protobuf-java:jar:2.4.0a:compile - omitted for conflict with 2.5.0)
|  +- (com.sun.jersey:jersey-core:jar:1.8:compile - omitted for conflict with 1.9)
|  +- (com.sun.jersey:jersey-json:jar:1.8:compile - omitted for conflict with 1.9)
|  +- (com.sun.jersey:jersey-server:jar:1.8:compile - omitted for conflict with 1.9)
|  +- javax.xml.bind:jaxb-api:jar:2.1:compile
|  |  \- javax.activation:activation:jar:1.1:compile
|  \- stax:stax-api:jar:1.0.1:compile
\- org.slf4j:slf4j-api:jar:1.7.5:compile

运行JAR的Java命令

java -cp HBaseIntro-0.0.1-SNAPSHOT-jar-with-dependencies.jar com.hbase_intro.HBaseIntro.HelloWorld arg1 arg2 arg3 agr4

2 个答案:

答案 0 :(得分:1)

您可能没有完全解决您的排除问题。即便如此,你也可以拉

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.5</version>
</dependency>

是pom.xml中第一个声明的依赖项,因此类路径会拾取最新的jar。

Maven正在使用&#34;最近赢的&#34;策略,因此如果您将所需的依赖项作为第一个声明,则将省略所有具有匹配的groupId和artifactId的传递。

你也应该明确地定义一个绑定(写在slf4j-api下面),&#39;因为第二次看,它来自传递依赖的绑定,这可以解释为什么你的排除不会出现这种情况。解决你的问题。不确定您使用哪种绑定,但尝试添加类似

的内容
   <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.5</version>
    </dependency>

并查看是否有帮助

答案 1 :(得分:0)

Slf4j在1.5和1.6版本之间引入了一些API不兼容性。较新的版本是向后兼容的,但如果您的应用程序使用较新的版本,而较旧的版本由maven解决,您将得到您正在遇到的问题。

对我来说最简单的解决方法是在依赖管理部分强制使用slf4j依赖版本。它相当于Master Slave的答案,只是它使用了用于此目的的机制。

看起来像这样:

<dependencyManagement>
   <dependencies>
       <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
          <version>1.7.5</version>
       </dependency>
        <!--exchange this one for whatever backend you want-->
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-log4j12</artifactId>
          <version>1.7.5</version>
       </dependency>
       <!--if you have dependencies that use commons-logging make sure that you exclude it from them and declare this one as well-->
       <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>jcl-over-slf4j</artifactId>
          <version>1.7.5</version>
       </dependency>      
   </dependencies>
</dependencyManagement>