简体   繁体   English

结合使用protobuf3和一些依赖于Java中protobuf2的库

[英]use protobuf3 with some lib which depends on protobuf2 in Java

I'm using protobuf3 to represent our data, while we need hbase to store the data, it seems like hbase depends on protobuf2. 我正在使用protobuf3表示我们的数据,尽管我们需要hbase来存储数据,但似乎hbase取决于protobuf2。

When i write the following line to create our hbase table 当我写以下行来创建我们的hbase表时

admin.createTable(desc);

then I got an Excepiton: NoClassDefFoundError: com/google/protobuf/LiteralByteString 然后我得到了一个Excepiton: NoClassDefFoundError: com/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 . 我尝试使用gradle的shadow插件将com.google.protobuf重定位到shadow.google.com,然后它抛出类似的消息NoClassDefFoundError: shadow/google/protobuf/LiteralByteString

  1. Create a sub-project, and name it 'hbase-wrapper' 创建一个子项目,并将其命名为“ hbase-wrapper”
  2. Move the dependencies for hbase to the new project 将hbase的依赖项移至新项目
  3. Shadow protobuf in the new project 新项目中的Shadow protobuf
  4. Add dependency to the sub-project on the main project 将依赖项添加到主项目的子项目中

Here's some snip code 这是一些代码

// 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')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM