结合使用protobuf3和一些依赖于Java中protobuf2的库 [英] use protobuf3 with some lib which depends on protobuf2 in Java

查看:445
本文介绍了结合使用protobuf3和一些依赖于Java中protobuf2的库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用protobuf3表示我们的数据,虽然我们需要hbase来存储数据,但似乎hbase依赖于protobuf2.

I'm using protobuf3 to represent our data, while we need hbase to store the data, it seems like hbase depends on protobuf2.

当我写以下行来创建我们的hbase表时

When i write the following line to create our hbase table

admin.createTable(desc);

然后我得到了一个Excepiton:NoClassDefFoundError: com/google/protobuf/LiteralByteString

then I got an Excepiton: NoClassDefFoundError: com/google/protobuf/LiteralByteString

我尝试使用 gradle的阴影插件将com.google.protobuf迁移到shadow.google. com,然后抛出类似的消息NoClassDefFoundError: shadow/google/protobuf/LiteralByteString.

I've tried using gradle's shadow plugin to relocate com.google.protobuf to shadow.google.com, then it throw a similar message NoClassDefFoundError: shadow/google/protobuf/LiteralByteString.

推荐答案

  1. 创建一个子项目,并将其命名为"hbase-wrapper"
  2. 将hbase的依赖项移到新项目中
  3. 新项目中的影子protobuf
  4. 在主项目上为子项目添加依赖项

这里有一些代码

// part of build.gradle of the sub-project
...
dependencies {
    compile group: 'org.apache.hbase', name: 'hbase-client', version: '1.2.4'
}

shadowJar {
    relocate('com.google.protobuf', 'hbasesaver.google.protobuf')
}

// part of build.gradle for main project
...
compile project(path: ':hbase-wrapper', configuration: 'shadow')

这篇关于结合使用protobuf3和一些依赖于Java中protobuf2的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆