我有一个语法为 proto2
另外,我需要使用 Spark (2.0.2) 和 HBase。我的项目是使用 Gradle 构建的。
现在,当我运行我的 Java 代码时,我得到这个错误:
Exception in thread "main" org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 3.0 failed 1 times, most recent failure: Lost task 0.0 in stage 3.0 (TID 3, localhost): java.lang.NoSuchMethodError: com.google.protobuf.Descriptors$Descriptor.getOneofs()Ljava/util/List;
at com.google.protobuf.GeneratedMessageV3$FieldAccessorTable.<init>(GeneratedMessageV3.java:1707)
at com.google.protobuf.AnyProto.<clinit>(AnyProto.java:52)
at com.google.protobuf.Any.getDescriptor(Any.java:129)
at com.google.protobuf.util.JsonFormat$ParserImpl.buildWellKnownTypeParsers(JsonFormat.java:1100)
at com.google.protobuf.util.JsonFormat$ParserImpl.<clinit>(JsonFormat.java:1094)
at com.google.protobuf.util.JsonFormat$Parser.merge(JsonFormat.java:277)
此堆栈跟踪与发布的问题非常相似 here ,但那里发布的决议不适用于我。
我尝试过的:
我变了
编译组:'com.google.protobuf',名称:'protobuf-java',版本:'2.5.0'
到
compile group: 'org.spark-project.protobuf', name: 'protobuf-java', version: '2.4.1-shaded'
如该链接所建议的,但仍然相同错误仍然存在。
非常感谢任何帮助!
最佳答案
好的,这是解决方案:
relocate
是救援之道。
在我的主程序中,我有一个像这样的 build.gradle:
dependencies {
compile project(path: ':utils:hbasewrapper', configuration: 'shadow')
}
apply plugin: 'com.github.johnrengelman.shadow'
shadowJar {
baseName = 'awesome-jar'
zip64 true
// This is to avoid the conflict between proto3 we are using and the proto2 hbase is using.
relocate ('com.google.protobuf', 'importer.com.google.protobuf')
}
然后,我创建了另一个 gradle 包,其中包含以下 build.gradle
group 'com.abc.hbasewrapper'
version '1.0-SNAPSHOT'
dependencies {
compile group: 'org.apache.hbase', name: 'hbase-client', version: '1.3.0'
compile group: 'org.apache.hbase', name: 'hbase-server', version: '1.2.2'
}
apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'
shadowJar {
baseName = 'hbasewrapper'
version = null
zip64 true
relocate ('com.google.protobuf', 'hbasewrapper.com.google.protobuf')
relocate ('io.netty', 'hbasewrapper.io.netty')
}
根本原因是 HBase 引用了 proto2 而我的程序使用了 proto3,因此导致了这个 NoSuchMethodError
错误。
解决方案是使用 relocate
,将 com.google.protobuf
重新定位到另一个 gradle 项目,其唯一目的是构建具有 proto2 的 hbase jar 文件。
希望对其他程序员有帮助! ^^
关于java - 带有 Spark 的 proto2 无法运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44123603/