Hbase 与 Codis 整合之 Maven 环境搭建

一、Codis 简介

Codis是一个分布式Redis解决方案,对于上层的应用来说,连接到Codis Proxy和连接原生的Redis服务器没有显着区别(不支持的命令列表),上层应用可以像使用单机的Redis一样使用,Codis底层会处理请求的转发,不停机的数据迁移等工作,所有后边的一切事情,对于前面的客户端来说是透明的,可以简单的认为后边连接的是一个内存无限大的Redis服务。

前提:已搭建好Codis集群

二、整合Maven

  
    
      org.apache.hbase
      hbase-client
      1.2.0-cdh5.7.0
    
    
      io.codis.jodis
      jodis
      0.4.1
    
  

三、报错

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/curator/shaded/com/google/common/collect/Maps
    at org.apache.curator.framework.recipes.cache.PathChildrenCache.(PathChildrenCache.java:77)
    at org.apache.curator.framework.recipes.cache.PathChildrenCache.(PathChildrenCache.java:174)
    at io.codis.jodis.RoundRobinJedisPool.(RoundRobinJedisPool.java:128)
    at io.codis.jodis.RoundRobinJedisPool.(RoundRobinJedisPool.java:69)
    at io.codis.jodis.RoundRobinJedisPool$Builder.build(RoundRobinJedisPool.java:408)
    at com.xcar.suggest.JodisClient.getPool(JodisClient.java:27)
    at com.xcar.suggest.test.main(test.java:9)
Caused by: java.lang.ClassNotFoundException: org.apache.curator.shaded.com.google.common.collect.Maps
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 7 more

四、原因分析:Jar包冲突

五、查看Maven树

E:\projects_ws\baoda\zhoupengbo\suggest\xcar_suggest_tag>mvn -Dverbose dependency:tree
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building xcar_suggest_tag 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ xcar_suggest_tag ---
[INFO] com.xcar.suggest:xcar_suggest_tag:jar:1.0-SNAPSHOT
[INFO] +- junit:junit:jar:4.11:test (scope not updated to compile)
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.apache.hbase:hbase-client:jar:1.2.0-cdh5.7.0:compile
[INFO] |  +- org.apache.hbase:hbase-annotations:jar:1.2.0-cdh5.7.0:compile
[INFO] |  |  +- (com.github.stephenc.findbugs:findbugs-annotations:jar:1.3.9-1:compile - omitted for duplicate)
[INFO] |  |  +- (log4j:log4j:jar:1.2.17:compile - omitted for duplicate)
[INFO] |  |  \- (junit:junit:jar:4.12:compile - omitted for conflict with 4.11)
[INFO] |  +- org.apache.hbase:hbase-common:jar:1.2.0-cdh5.7.0:compile
[INFO] |  |  +- (org.apache.hbase:hbase-protocol:jar:1.2.0-cdh5.7.0:compile - omitted for duplicate)
[INFO] |  |  +- (org.apache.hbase:hbase-annotations:jar:1.2.0-cdh5.7.0:compile - omitted for duplicate)
[INFO] |  |  +- (com.google.guava:guava:jar:12.0.1:compile - omitted for duplicate)
[INFO] |  |  +- (commons-logging:commons-logging:jar:1.2:compile - omitted for duplicate)
[INFO] |  |  +- (commons-codec:commons-codec:jar:1.9:compile - omitted for duplicate)
[INFO] |  |  +- (commons-lang:commons-lang:jar:2.6:compile - omitted for duplicate)
[INFO] |  |  +- commons-collections:commons-collections:jar:3.2.2:compile
[INFO] |  |  +- (commons-io:commons-io:jar:2.4:compile - omitted for duplicate)
[INFO] |  |  +- (com.google.protobuf:protobuf-java:jar:2.5.0:compile - omitted for duplicate)
[INFO] |  |  +- org.mortbay.jetty:jetty-util:jar:6.1.26.cloudera.4:compile
[INFO] |  |  +- (org.apache.htrace:htrace-core:jar:3.2.0-incubating:compile - omitted for duplicate)
[INFO] |  |  +- (org.apache.hadoop:hadoop-annotations:jar:2.6.0-cdh5.7.0:compile - omitted for duplicate)
[INFO] |  |  +- (org.apache.hadoop:hadoop-common:jar:2.6.0-cdh5.7.0:compile - omitted for duplicate)
[INFO] |  |  +- org.apache.hadoop:hadoop-core:jar:2.6.0-mr1-cdh5.7.0:compile
[INFO] |  |  |  +- (commons-cli:commons-cli:jar:1.2:compile - omitted for duplicate)
[INFO] |  |  |  +- (xmlenc:xmlenc:jar:0.52:compile - omitted for duplicate)
[INFO] |  |  |  +- (commons-httpclient:commons-httpclient:jar:3.1:compile - omitted for duplicate)
[INFO] |  |  |  +- (commons-codec:commons-codec:jar:1.4:compile - omitted for conflict with 1.9)
[INFO] |  |  |  +- (commons-net:commons-net:jar:3.1:compile - omitted for duplicate)
[INFO] |  |  |  +- (org.mortbay.jetty:jetty:jar:6.1.26.cloudera.2:compile - omitted for conflict with 6.1.26.cloudera.4)
[INFO] |  |  |  +- (org.mortbay.jetty:jetty-util:jar:6.1.26.cloudera.2:compile - omitted for conflict with 6.1.26.cloudera.4)
[INFO] |  |  |  +- tomcat:jasper-runtime:jar:5.5.23:compile
[INFO] |  |  |  |  +- (javax.servlet:servlet-api:jar:2.4:compile - omitted for conflict with 2.5)
[INFO] |  |  |  |  \- (commons-el:commons-el:jar:1.0:compile - omitted for duplicate)
[INFO] |  |  |  +- tomcat:jasper-compiler:jar:5.5.23:compile
[INFO] |  |  |  +- (org.codehaus.jackson:jackson-core-asl:jar:1.8.8:compile - omitted for duplicate)
[INFO] |  |  |  +- (org.codehaus.jackson:jackson-mapper-asl:jar:1.8.8:compile - omitted for duplicate)
[INFO] |  |  |  +- javax.servlet.jsp:jsp-api:jar:2.1:compile
[INFO] |  |  |  +- commons-el:commons-el:jar:1.0:compile
[INFO] |  |  |  |  \- (commons-logging:commons-logging:jar:1.0.3:compile - omitted for conflict with 1.2)
[INFO] |  |  |  +- (net.java.dev.jets3t:jets3t:jar:0.6.1:compile - omitted for conflict with 0.9.0)
[INFO] |  |  |  +- (javax.servlet:servlet-api:jar:2.5:compile - omitted for duplicate)
[INFO] |  |  |  +- hsqldb:hsqldb:jar:1.8.0.10:compile
[INFO] |  |  |  +- org.eclipse.jdt:core:jar:3.1.1:compile
[INFO] |  |  |  \- (org.apache.zookeeper:zookeeper:jar:3.4.5-cdh5.7.0:compile - omitted for duplicate)
[INFO] |  |  +- (com.github.stephenc.findbugs:findbugs-annotations:jar:1.3.9-1:compile - omitted for duplicate)
[INFO] |  |  +- (log4j:log4j:jar:1.2.17:compile - omitted for duplicate)
[INFO] |  |  \- (junit:junit:jar:4.12:compile - omitted for conflict with 4.11)
[INFO] |  +- org.apache.hbase:hbase-protocol:jar:1.2.0-cdh5.7.0:compile
[INFO] |  |  +- (org.apache.hbase:hbase-annotations:jar:1.2.0-cdh5.7.0:compile - omitted for duplicate)
[INFO] |  |  +- (com.google.protobuf:protobuf-java:jar:2.5.0:compile - omitted for duplicate)
[INFO] |  |  +- (commons-logging:commons-logging:jar:1.2:compile - omitted for duplicate)
[INFO] |  |  +- (com.github.stephenc.findbugs:findbugs-annotations:jar:1.3.9-1:compile - omitted for duplicate)
[INFO] |  |  +- (log4j:log4j:jar:1.2.17:compile - omitted for duplicate)
[INFO] |  |  \- (junit:junit:jar:4.12:compile - omitted for conflict with 4.11)
[INFO] |  +- commons-codec:commons-codec:jar:1.9:compile
[INFO] |  +- commons-io:commons-io:jar:2.4:compile
[INFO] |  +- commons-lang:commons-lang:jar:2.6:compile
[INFO] |  +- commons-logging:commons-logging:jar:1.2:compile
[INFO] |  +- com.google.guava:guava:jar:12.0.1:compile
[INFO] |  |  \- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO] |  +- com.google.protobuf:protobuf-java:jar:2.5.0:compile
[INFO] |  +- io.netty:netty-all:jar:4.0.23.Final:compile
[INFO] |  +- org.apache.zookeeper:zookeeper:jar:3.4.5-cdh5.7.0:compile
[INFO] |  |  +- (org.slf4j:slf4j-api:jar:1.7.5:compile - omitted for conflict with 1.7.12)
[INFO] |  |  +- org.slf4j:slf4j-log4j12:jar:1.7.5:compile
[INFO] |  |  |  +- (org.slf4j:slf4j-api:jar:1.7.5:compile - omitted for duplicate)
[INFO] |  |  |  \- (log4j:log4j:jar:1.2.17:compile - omitted for duplicate)
[INFO] |  |  \- (log4j:log4j:jar:1.2.17:compile - omitted for duplicate)
[INFO] |  +- org.apache.htrace:htrace-core:jar:3.2.0-incubating:compile
[INFO] |  +- org.codehaus.jackson:jackson-mapper-asl:jar:1.8.8:compile
[INFO] |  |  \- org.codehaus.jackson:jackson-core-asl:jar:1.8.8:compile
[INFO] |  +- org.jruby.jcodings:jcodings:jar:1.0.8:compile
[INFO] |  +- org.jruby.joni:joni:jar:2.1.2:compile
[INFO] |  |  \- (org.jruby.jcodings:jcodings:jar:1.0.8:compile - omitted for duplicate)
[INFO] |  +- com.yammer.metrics:metrics-core:jar:2.2.0:compile
[INFO] |  |  \- (org.slf4j:slf4j-api:jar:1.7.2:compile - omitted for conflict with 1.7.5)
[INFO] |  +- org.apache.hadoop:hadoop-common:jar:2.6.0-cdh5.7.0:compile
[INFO] |  |  +- (org.apache.hadoop:hadoop-annotations:jar:2.6.0-cdh5.7.0:compile - omitted for duplicate)
[INFO] |  |  +- (com.google.guava:guava:jar:11.0.2:compile - omitted for conflict with 12.0.1)
[INFO] |  |  +- commons-cli:commons-cli:jar:1.2:compile
[INFO] |  |  +- org.apache.commons:commons-math3:jar:3.1.1:compile
[INFO] |  |  +- xmlenc:xmlenc:jar:0.52:compile
[INFO] |  |  +- commons-httpclient:commons-httpclient:jar:3.1:compile
[INFO] |  |  |  +- (commons-logging:commons-logging:jar:1.0.4:compile - omitted for conflict with 1.2)
[INFO] |  |  |  \- (commons-codec:commons-codec:jar:1.2:compile - omitted for conflict with 1.9)
[INFO] |  |  +- (commons-codec:commons-codec:jar:1.4:compile - omitted for conflict with 1.9)
[INFO] |  |  +- (commons-io:commons-io:jar:2.4:compile - omitted for duplicate)
[INFO] |  |  +- commons-net:commons-net:jar:3.1:compile
[INFO] |  |  +- (commons-collections:commons-collections:jar:3.2.2:compile - omitted for duplicate)
[INFO] |  |  +- org.mortbay.jetty:jetty:jar:6.1.26.cloudera.4:compile
[INFO] |  |  |  \- (org.mortbay.jetty:jetty-util:jar:6.1.26.cloudera.4:compile - omitted for duplicate)
[INFO] |  |  +- (org.mortbay.jetty:jetty-util:jar:6.1.26.cloudera.4:compile - omitted for duplicate)
[INFO] |  |  +- com.sun.jersey:jersey-core:jar:1.9:compile
[INFO] |  |  +- com.sun.jersey:jersey-json:jar:1.9:compile
[INFO] |  |  |  +- org.codehaus.jettison:jettison:jar:1.1:compile
[INFO] |  |  |  +- com.sun.xml.bind:jaxb-impl:jar:2.2.3-1:compile
[INFO] |  |  |  |  \- javax.xml.bind:jaxb-api:jar:2.2.2:compile
[INFO] |  |  |  |     +- javax.xml.stream:stax-api:jar:1.0-2:compile
[INFO] |  |  |  |     \- javax.activation:activation:jar:1.1:compile
[INFO] |  |  |  +- (org.codehaus.jackson:jackson-core-asl:jar:1.8.3:compile - omitted for conflict with 1.8.8)
[INFO] |  |  |  +- (org.codehaus.jackson:jackson-mapper-asl:jar:1.8.3:compile - omitted for conflict with 1.8.8)
[INFO] |  |  |  +- org.codehaus.jackson:jackson-jaxrs:jar:1.8.3:compile
[INFO] |  |  |  |  +- (org.codehaus.jackson:jackson-core-asl:jar:1.8.3:compile - omitted for conflict with 1.8.8)
[INFO] |  |  |  |  \- (org.codehaus.jackson:jackson-mapper-asl:jar:1.8.3:compile - omitted for conflict with 1.8.8)
[INFO] |  |  |  +- org.codehaus.jackson:jackson-xc:jar:1.8.3:compile
[INFO] |  |  |  |  +- (org.codehaus.jackson:jackson-core-asl:jar:1.8.3:compile - omitted for conflict with 1.8.8)
[INFO] |  |  |  |  \- (org.codehaus.jackson:jackson-mapper-asl:jar:1.8.3:compile - omitted for conflict with 1.8.8)
[INFO] |  |  |  \- (com.sun.jersey:jersey-core:jar:1.9:compile - omitted for duplicate)
[INFO] |  |  +- (commons-el:commons-el:jar:1.0:compile - scope updated from runtime; omitted for duplicate)
[INFO] |  |  +- (commons-logging:commons-logging:jar:1.1.3:compile - omitted for conflict with 1.2)
[INFO] |  |  +- (log4j:log4j:jar:1.2.17:compile - omitted for duplicate)
[INFO] |  |  +- net.java.dev.jets3t:jets3t:jar:0.9.0:compile
[INFO] |  |  |  +- (commons-codec:commons-codec:jar:1.4:compile - omitted for conflict with 1.9)
[INFO] |  |  |  +- (commons-logging:commons-logging:jar:1.1.1:compile - omitted for conflict with 1.2)
[INFO] |  |  |  +- (org.apache.httpcomponents:httpclient:jar:4.1.2:compile - omitted for conflict with 4.2.5)
[INFO] |  |  |  +- org.apache.httpcomponents:httpcore:jar:4.1.2:compile
[INFO] |  |  |  \- com.jamesmurty.utils:java-xmlbuilder:jar:0.4:compile
[INFO] |  |  +- (commons-lang:commons-lang:jar:2.6:compile - omitted for duplicate)
[INFO] |  |  +- commons-configuration:commons-configuration:jar:1.6:compile
[INFO] |  |  |  +- (commons-collections:commons-collections:jar:3.2.1:compile - omitted for conflict with 3.2.2)
[INFO] |  |  |  +- (commons-lang:commons-lang:jar:2.4:compile - omitted for conflict with 2.6)
[INFO] |  |  |  +- (commons-logging:commons-logging:jar:1.1.1:compile - omitted for conflict with 1.2)
[INFO] |  |  |  +- commons-digester:commons-digester:jar:1.8:compile
[INFO] |  |  |  |  +- commons-beanutils:commons-beanutils:jar:1.7.0:compile
[INFO] |  |  |  |  |  \- (commons-logging:commons-logging:jar:1.0.3:compile - omitted for conflict with 1.2)
[INFO] |  |  |  |  \- (commons-logging:commons-logging:jar:1.1:compile - omitted for conflict with 1.2)
[INFO] |  |  |  \- commons-beanutils:commons-beanutils-core:jar:1.8.0:compile
[INFO] |  |  |     \- (commons-logging:commons-logging:jar:1.1.1:compile - omitted for conflict with 1.2)
[INFO] |  |  +- (org.slf4j:slf4j-api:jar:1.7.5:compile - omitted for duplicate)
[INFO] |  |  +- (org.slf4j:slf4j-log4j12:jar:1.7.5:runtime - omitted for duplicate)
[INFO] |  |  +- (org.codehaus.jackson:jackson-core-asl:jar:1.8.8:compile - omitted for duplicate)
[INFO] |  |  +- (org.codehaus.jackson:jackson-mapper-asl:jar:1.8.8:compile - omitted for duplicate)
[INFO] |  |  +- org.apache.avro:avro:jar:1.7.6-cdh5.7.0:compile
[INFO] |  |  |  +- (org.codehaus.jackson:jackson-core-asl:jar:1.8.8:compile - omitted for duplicate)
[INFO] |  |  |  +- (org.codehaus.jackson:jackson-mapper-asl:jar:1.8.8:compile - omitted for duplicate)
[INFO] |  |  |  +- com.thoughtworks.paranamer:paranamer:jar:2.3:compile
[INFO] |  |  |  +- org.xerial.snappy:snappy-java:jar:1.0.4.1:compile
[INFO] |  |  |  +- (org.apache.commons:commons-compress:jar:1.4.1:compile - omitted for duplicate)
[INFO] |  |  |  \- (org.slf4j:slf4j-api:jar:1.6.4:compile - omitted for conflict with 1.7.5)
[INFO] |  |  +- (com.google.protobuf:protobuf-java:jar:2.5.0:compile - omitted for duplicate)
[INFO] |  |  +- com.google.code.gson:gson:jar:2.2.4:compile
[INFO] |  |  +- (org.apache.hadoop:hadoop-auth:jar:2.6.0-cdh5.7.0:compile - omitted for duplicate)
[INFO] |  |  +- com.jcraft:jsch:jar:0.1.42:compile
[INFO] |  |  +- org.apache.curator:curator-client:jar:2.7.1:compile
[INFO] |  |  |  +- (org.slf4j:slf4j-api:jar:1.7.6:compile - omitted for conflict with 1.7.5)
[INFO] |  |  |  +- (org.apache.zookeeper:zookeeper:jar:3.4.6:compile - omitted for conflict with 3.4.5-cdh5.7.0)
[INFO] |  |  |  \- (com.google.guava:guava:jar:16.0.1:compile - omitted for conflict with 12.0.1)
[INFO] |  |  +- (org.apache.curator:curator-recipes:jar:2.7.1:compile - omitted for conflict with 2.12.0)
[INFO] |  |  +- (com.google.code.findbugs:jsr305:jar:3.0.0:compile - omitted for conflict with 1.3.9)
[INFO] |  |  +- org.apache.htrace:htrace-core4:jar:4.0.1-incubating:compile
[INFO] |  |  +- (org.apache.zookeeper:zookeeper:jar:3.4.5-cdh5.7.0:compile - omitted for duplicate)
[INFO] |  |  \- org.apache.commons:commons-compress:jar:1.4.1:compile
[INFO] |  |     \- org.tukaani:xz:jar:1.0:compile
[INFO] |  +- org.apache.hadoop:hadoop-annotations:jar:2.6.0-cdh5.7.0:compile
[INFO] |  +- org.apache.hadoop:hadoop-auth:jar:2.6.0-cdh5.7.0:compile
[INFO] |  |  +- (org.slf4j:slf4j-api:jar:1.7.5:compile - omitted for duplicate)
[INFO] |  |  +- (commons-codec:commons-codec:jar:1.4:compile - omitted for conflict with 1.9)
[INFO] |  |  +- (log4j:log4j:jar:1.2.17:runtime - omitted for duplicate)
[INFO] |  |  +- (org.slf4j:slf4j-log4j12:jar:1.7.5:runtime - omitted for duplicate)
[INFO] |  |  +- org.apache.httpcomponents:httpclient:jar:4.2.5:compile
[INFO] |  |  |  +- (org.apache.httpcomponents:httpcore:jar:4.2.4:compile - omitted for conflict with 4.1.2)
[INFO] |  |  |  +- (commons-logging:commons-logging:jar:1.1.1:compile - omitted for conflict with 1.2)
[INFO] |  |  |  \- (commons-codec:commons-codec:jar:1.6:compile - omitted for conflict with 1.9)
[INFO] |  |  +- org.apache.directory.server:apacheds-kerberos-codec:jar:2.0.0-M15:compile
[INFO] |  |  |  +- org.apache.directory.server:apacheds-i18n:jar:2.0.0-M15:compile
[INFO] |  |  |  |  \- (org.slf4j:slf4j-api:jar:1.7.5:compile - omitted for duplicate)
[INFO] |  |  |  +- org.apache.directory.api:api-asn1-api:jar:1.0.0-M20:compile
[INFO] |  |  |  |  \- (org.slf4j:slf4j-api:jar:1.7.5:compile - omitted for duplicate)
[INFO] |  |  |  +- org.apache.directory.api:api-util:jar:1.0.0-M20:compile
[INFO] |  |  |  |  \- (org.slf4j:slf4j-api:jar:1.7.5:compile - omitted for duplicate)
[INFO] |  |  |  \- (org.slf4j:slf4j-api:jar:1.7.5:compile - omitted for duplicate)
[INFO] |  |  +- (org.apache.zookeeper:zookeeper:jar:3.4.5-cdh5.7.0:compile - omitted for duplicate)
[INFO] |  |  \- org.apache.curator:curator-framework:jar:2.7.1:compile
[INFO] |  |     +- (org.apache.curator:curator-client:jar:2.7.1:compile - omitted for duplicate)
[INFO] |  |     +- (org.apache.zookeeper:zookeeper:jar:3.4.6:compile - omitted for conflict with 3.4.5-cdh5.7.0)
[INFO] |  |     \- (com.google.guava:guava:jar:16.0.1:compile - omitted for conflict with 12.0.1)
[INFO] |  +- com.github.stephenc.findbugs:findbugs-annotations:jar:1.3.9-1:compile
[INFO] |  \- (junit:junit:jar:4.12:compile - omitted for conflict with 4.11)
[INFO] +- log4j:log4j:jar:1.2.17:compile
[INFO] +- com.alibaba:fastjson:jar:1.2.29:compile
[INFO] \- io.codis.jodis:jodis:jar:0.4.1:compile
[INFO]    +- redis.clients:jedis:jar:2.9.0:compile
[INFO]    |  \- org.apache.commons:commons-pool2:jar:2.4.2:compile
[INFO]    +- org.apache.curator:curator-recipes:jar:2.12.0:compile
[INFO]    |  \- (org.apache.curator:curator-framework:jar:2.12.0:compile - omitted for conflict with 2.7.1)
[INFO]    +- org.slf4j:slf4j-api:jar:1.7.12:compile
[INFO]    +- (com.google.guava:guava:jar:19.0:compile - omitted for conflict with 12.0.1)
[INFO]    \- com.fasterxml.jackson.core:jackson-databind:jar:2.7.1-1:compile
[INFO]       +- com.fasterxml.jackson.core:jackson-annotations:jar:2.7.0:compile
[INFO]       \- com.fasterxml.jackson.core:jackson-core:jar:2.7.1:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.980 s
[INFO] Finished at: 2018-05-25T10:02:25+08:00
[INFO] Final Memory: 20M/305M
[INFO] ------------------------------------------------------------------------

发现Hbase与Codis依赖了不同版本的 curator-recipes.

解除依赖冲突

修改pom.xml文件:


    
      org.apache.hbase
      hbase-client
      1.2.0-cdh5.7.0
    

    
      io.codis.jodis
      jodis
      0.4.1
      
      
        org.apache.curator
        curator-recipes
      
      
    
  

如此,即可编码开发了。

你可能感兴趣的:(Hbase 与 Codis 整合之 Maven 环境搭建)