我正在尝试仅使用本地依赖项来编译和运行 java grpc 客户端,但出现以下错误:
Exception in thread "main" java.lang.NoClassDefFoundError: io/netty/channel/socket/nio/NioSocketChannel
at io.grpc.netty.NettyChannelBuilder.<init>(NettyChannelBuilder.java:69)
at io.grpc.netty.NettyChannelBuilder.<init>(NettyChannelBuilder.java:103)
at io.grpc.netty.NettyChannelBuilder.forAddress(NettyChannelBuilder.java:91)
at io.grpc.netty.NettyChannelProvider.builderForAddress(NettyChannelProvider.java:52)
at io.grpc.netty.NettyChannelProvider.builderForAddress(NettyChannelProvider.java:38)
at io.grpc.ManagedChannelBuilder.forAddress(ManagedChannelBuilder.java:45)
at myclient.MyClient.<init>(myClient.java:28)
at myclient.MyClient.main(myClient.java:90)
Caused by: java.lang.ClassNotFoundException: io.netty.channel.socket.nio.NioSocketChannel
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 8 more
这是我的gradle文件:
apply plugin: 'java'
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile name: 'grpc-netty-1.0.3'
compile name: 'grpc-okhttp-1.0.3'
compile name: 'grpc-protobuf-1.0.3'
compile name: 'grpc-stub-1.0.3'
compile name: 'grpc-core-1.0.3'
compile name: 'guava-20.0'
compile name: 'protobuf-java-3.1.0'
}
jar {
manifest {
attributes(
'Main-Class': 'myclient.myClient',
'Class-Path': configurations.compile.collect {it.getName() }.join(' ')
)
}
}
该程序将编译,但不会运行。我已经从 protos 生成了我的 java 文件,并验证我使用了正确的 protoc 和 protoc-gen-grpc-java 来对应我正在使用的 jar 库。任何帮助表示赞赏。