3

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.

0

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks. I added the jar and got this error: pastebin.com/tyPKJvPT
@CoderCole, I dont have access to pastebin
Ok, I tried adding all the dependencies and now I get a different NoClassDefFoundError concerning io/grpc/Context$CancellationListener
I finally got it to work adding grpc-context, grpc-protobuf-lite, and netty-all jars. Thanks again @hanumant

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.