zoukankan      html  css  js  c++  java
  • HBase中报错 java.lang.NoClassDefFoundError: com/google/protobuf/LiteralByteString

    Protobuf(全称 Protocol Buffers)是 Google 开发的一种数据描述语言,能够将结构化数据序列化,可用于数据存储、通信协议等方面。在 HBase 里面用使用了 Protobuf 的类库。

    版本:
    HBase:1.3.1
    MySQL:8.0.13

    错误报告

    org.apache.hadoop.hbase.DoNotRetryIOException: java.lang.NoClassDefFoundError: com/google/protobuf/LiteralByteString

    原因分析
    运行mvn dependency:tree后发现MySQL8.0.13中有com.google.protobuf:protobuf-java:jar:3.6.1:compile。


    查看了3.6.x的protobuf 的源码,里面并没有LiteralByteString这个类。
    https://github.com/protocolbuffers/protobuf/tree/3.6.x/java/core/src/main/java/com/google/protobuf

    查看了2.6.1及以下版本的protobuf 的源码,里面存在LiteralByteString这个类。
    https://github.com/google/protobuf/blob/v2.5.0/java/src/main/java/com/google/protobuf/LiteralByteString.java

    解决方法尝试
    将maven中的MySQL8.0.13的引入注释掉或MySQL版本换成低版本,如5.0.7,可以正常运行。

    原因猜测
    应用程序已经获得了另外一个版本的Protobuf(如3.6.1)并将其放在类路径中。建议在应用程序上运行mvn dependency:tree以查看它是否正在拾取不兼容的Protobuf依赖项(可能是传递性的)。如果应用程序的Maven依赖关系看起来很好,那么当你启动应用程序并拾取一个不正确的Protobuf版本时,可能是在运行时重载了类路径。

    解决办法
    1、降低protobuf版本(实操可用)

    <dependency>
      <groupId>com.google.protobuf</groupId>
      <artifactId>protobuf-java</artifactId>
      <version>2.5.0</version>
    </dependency>


    2、将客户端的Protobuf类库重命名(尝试了下还是不行,应该是我本身项目哪还有问题)

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.4.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <relocations>
                        <relocation>
                            <pattern>com.google.protobuf</pattern>
                            <shadedPattern>com.fazi.google.protobuf</shadedPattern>
                        </relocation>
                    </relocations>
                </configuration>
            </plugin>
        </plugins>
    </build>


    3、使用hbase-shaded-client(实操可用)
    hbase-shaded-client是社区里有人将HBase里面比较常见的依赖进行了重命名,在pom文件中我们可以将引入的hbase-client替换成hbase-shaded-client

    <dependency>
                <groupId>org.apache.hbase</groupId>
                <artifactId>hbase-shaded-client</artifactId>
                <version>1.3.1</version>
    </dependency>


    参考地址:
    https://stackoverflow.com/questions/41734330/protobuf-error-hbase-createtable-put-in-java-codeprotobuf-literalbytestring
    https://www.iteblog.com/archives/2463.html
    ---------------------
    作者:发孖、
    来源:CSDN
    原文:https://blog.csdn.net/xcf111/article/details/86692591
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    UML中的构件图
    Extjs4 中的gird
    【转载】C#实现线程安全的网络流
    [转载]组播
    【转载】wcf综合运用之:大文件异步断点续传
    【转载】WCF热门问题编程示例(4):WCF客户端如何异步调用WCF服务?
    【转载】特殊用途的IP地址介绍
    [转载]C# HashTable
    c宏定义实战
    c异或加密与解密
  • 原文地址:https://www.cnblogs.com/ao-xiang/p/10871558.html
Copyright © 2011-2022 走看看