Java grpc 运行时错误
Java grpc runtime error
我正在尝试编译 运行 一个 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 库。感谢任何帮助。
你需要netty jar文件,从这里下载
https://mvnrepository.com/artifact/io.netty/netty-all/4.0.0.CR1
别忘了将它添加到类路径中
更新:
不好意思,请下载所有依赖的jar文件。检查 => 编译依赖项 (16)
https://mvnrepository.com/artifact/io.netty/netty-codec-http2/5.0.0.Alpha2
我正在尝试编译 运行 一个 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 库。感谢任何帮助。
你需要netty jar文件,从这里下载
https://mvnrepository.com/artifact/io.netty/netty-all/4.0.0.CR1
别忘了将它添加到类路径中
更新:
不好意思,请下载所有依赖的jar文件。检查 => 编译依赖项 (16)
https://mvnrepository.com/artifact/io.netty/netty-codec-http2/5.0.0.Alpha2