我试图在一个介绍项目与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>
依赖树(我生成了带有verbose标志的依赖树,看起来slf4j1.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条答案
按热度按时间emeijp431#
你可能还没有完全解决你的排除问题。即使这样,你也可以
作为pom.xml中第一个声明的依赖项,以便类路径获取最新的jar。
maven使用的是“最近赢”策略,因此如果您首先声明了所需的依赖项,那么所有具有匹配groupid和artifactid的可传递项都将被省略。
你也应该明确地定义一个绑定(写在slf4japi下面),因为再看一眼,它是来自可传递依赖项的绑定,这可以解释为什么排除不能解决你的问题。不确定您使用哪种绑定,但请尝试添加以下内容
看看有没有用
ozxc1zmp2#
slf4j在1.5和1.6版本之间引入了一些api不兼容。较新的版本是向后兼容的,但是如果您的应用程序使用较新的版本,而较旧的版本得到maven的解决,那么您将得到正是您所遇到的问题。
对我来说,最简单的解决方法是在依赖关系管理部分强制使用slf4j依赖关系版本。它相当于主从的答案,只是它使用的机制是为了这个目的。
它看起来是这样的: