You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Eclipse插件开发使用gRPC调用遇类找不到等异常求助

Eclipse插件中gRPC客户端的类加载问题

我正在开发一款Eclipse插件,使其作为gRPC客户端通过gRPC调用与其他应用通信,已使用目标平台集成所需的所有gRPC依赖。

通道创建问题

当尝试使用ManagedChannelBuilder创建ManagedChannel时:

ManagedChannel channel2 = ManagedChannelBuilder.forAddress("localhost", port).usePlaintext().build();

系统提示无可用的通道构建器,但我已添加okhttp依赖。改用OkHttpChannelBuilder手动创建ManagedChannel可成功创建通道:

channel1 = io.grpc.okhttp.OkHttpChannelBuilder.forAddress("localhost", port)
                .nameResolverFactory(new DnsNameResolverProvider())
                .usePlaintext()
                .build();

gRPC调用时的类加载异常

使用上述手动创建的通道执行请求时,抛出java.lang.NoClassDefFoundError: io/grpc/Context异常:

业务代码

public String stopGDBHost() {
        GDBHostServiceBlockingStub gdbStub = GDBHostServiceGrpc.newBlockingStub(channel1);
                 
        StatusResponse response = gdbStub.stopGDBHost(null);
          
        return response.getErrorMessage();
          
    }

异常栈信息

java.lang.NoClassDefFoundError: io/grpc/Context
    at io.grpc.internal.ManagedChannelImpl$RealChannel.newCall(ManagedChannelImpl.java:994)
    at io.grpc.internal.ManagedChannelImpl.newCall(ManagedChannelImpl.java:907)
    at io.grpc.internal.ForwardingManagedChannel.newCall(ForwardingManagedChannel.java:63)
    at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:150)

奇怪的是io.grpc.Context类已在类路径中,但仍无法被找到。以下是我的插件依赖配置及grpc-core、grpc-context的Manifest文件内容:

插件Manifest配置

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Test2
Bundle-SymbolicName: Test2;singleton:=true
Bundle-Version: 1.0.0.qualifier
Require-Bundle: javax.annotation;bundle-version="1.3.5",
 org.eclipse.ui;bundle-version="3.202.0",
 wrapped.io.grpc.grpc-stub;bundle-version="1.55.1",
 wrapped.io.grpc.grpc-okhttp;bundle-version="1.55.1",
 wrapped.io.grpc.grpc-protobuf;bundle-version="1.55.1",
 com.google.guava;bundle-version="31.1.0",
 wrapped.com.google.protobuf.protobuf-java;bundle-version="3.22.3",
 wrapped.io.grpc.grpc-core;bundle-version="1.55.1",
 wrapped.io.grpc.grpc-api;bundle-version="1.55.1",
 wrapped.io.grpc.grpc-context;bundle-version="1.55.1"
Automatic-Module-Name: Test2
Bundle-ClassPath: .
Bundle-RequiredExecutionEnvironment: JavaSE-17
DynamicImport-Package: *

grpc-context的Manifest

Manifest-Version: 1.0
Bnd-LastModified: 1688104218240
Bundle-ManifestVersion: 2
Bundle-Name: Bundle derived from maven artifact io.grpc:grpc-context:1.55.1
Bundle-SymbolicName: wrapped.io.grpc.grpc-context
Bundle-Version: 1.55.1
Created-By: 17.0.7 (Eclipse Adoptium)
DynamicImport-Package: *
Export-Package: io.grpc;version="1.55.1"
Implementation-Title: jar
Implementation-Version: 1.55.1
Import-Package: io.grpc.override;resolution:=optional
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.7))"
Tool: Bnd-6.4.0.202211291949

grpc-core的Manifest

Manifest-Version: 1.0
Bnd-LastModified: 1688104213114
Bundle-ManifestVersion: 2
Bundle-Name: Bundle derived from maven artifact io.grpc:grpc-core:1.55.1
Bundle-SymbolicName: wrapped.io.grpc.grpc-core
Bundle-Version: 1.55.1
Created-By: 17.0.7 (Eclipse Adoptium)
DynamicImport-Package: *
Export-Package: io.grpc.inprocess;version="1.55.1";uses:="io.grpc,io.grpc.internal",io.grpc.internal;version="1.55.1";uses:="com.google.common.base,com.google.common.util.concurrent,io.grpc,javax.annotation",io.grpc.util;version="1.55.1";uses:="io.grpc,io.grpc.internal,javax.annotation,javax.net.ssl"
Implementation-Title: jar
Implementation-Version: 1.55.1
Import-Package: com.google.common.base;resolution:=optional;version="[31.1,32)",com.google.common.collect;resolution:=optional;version="[31.1,32)",com.google.common.io;resolution:=optional;version="[31.1,32)",com.google.common.math;resolution:=optional;version="[31.1,32)",com.google.common.util.concurrent;resolution:=optional;version="[31.1,32)",com.google.gson.stream;resolution:=optional;version="[2.9,3)",com.sun.jndi.dns;resolution:=optional,io.grpc;resolution:=optional;version="[1.55,2)",io.grpc.census;resolution:=optional,io.perfmark;resolution:=optional;version="[0.25,1)",javax.annotation;resolution:=optional,javax.naming;resolution:=optional,javax.naming.directory;resolution:=optional,javax.net.ssl;resolution:=optional,org.conscrypt;resolution:=optional
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
Tool: Bnd-6.4.0.202211291949

请问有人成功在Eclipse插件开发中运行gRPC了吗?或者有人知道如何解决这个问题吗?


内容的提问来源于stack exchange,提问作者Tim Schmid

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 13:42:48