将 protobuf3 与一些依赖于 Java 中的 protobuf2 的库一起使用

2024-03-14

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

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

admin.createTable(desc);

然后我得到一个例外:NoClassDefFoundError: com/google/protobuf/LiteralByteString

我尝试过使用gradle的影子插件 http://imperceptiblethoughts.com/shadow/将 com.google.protobuf 重新定位到shadow.google.com,然后它会抛出类似的消息NoClassDefFoundError: shadow/google/protobuf/LiteralByteString.


  1. 创建一个子项目,并将其命名为“hbase-wrapper”
  2. 将 hbase 的依赖项移至新项目
  3. 新项目中的 Shadow 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')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将 protobuf3 与一些依赖于 Java 中的 protobuf2 的库一起使用 的相关文章

随机推荐