Java grpc runtime error

7.7k views Asked by At

I am trying to compile and a run a java grpc client using only local dependencies, but I am getting the following error:

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

Here is my gradle file:

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(' ')
        )
    }
}

The program will compile, but not run. I have already generated my java files from the protos and verified I have used the correct protoc and protoc-gen-grpc-java to correspond with the jar libraries I'm using. Any help is appreciated.

1

There are 1 answers

4
hanumant On BEST ANSWER

you need the netty jar file, download from here

https://mvnrepository.com/artifact/io.netty/netty-all/4.0.0.CR1

And dont forget to add it to your classpath

UPDATE:

My bad, please download all dependent jar files. check for => Compile Dependencies (16)

https://mvnrepository.com/artifact/io.netty/netty-codec-http2/5.0.0.Alpha2