Compiling GRPC server/client in java

1,390 views
Skip to first unread message

kj...@conti-x.com

unread,
Oct 27, 2015, 4:45:31 PM10/27/15
to grpc.io
I'm having a lot of trouble figuring out how to compile a GRPC Java server. I looked all over the grpc.io website and closest thing I found was this: http://www.grpc.io/docs/#quick-start , where I run ../gradlew -PskipCodegen=true installDist to build, and ./build/install/grpc-examples/bin/hello-world-client to run the client. This all works, but only for the hello-world tutorial. I have no idea how to do this for my own client/server. I'm able to generate the client/server protobufs using the .proto file. I looked in their readme and Java tutorial and couldn't find out how to compile the actual server (and client) after I write them https://github.com/grpc/grpc-java/blob/master/examples/README.md  http://www.grpc.io/docs/tutorials/basic/java.html#try-it-out . Unless there's documentation im missing, does anyone know how to compile a server and client that implements the GRPC classes generated from the .proto file? I did spend a fair amount of time searching. Any advice is much appreciated, thanks.

Eric Anderson

unread,
Oct 27, 2015, 5:18:04 PM10/27/15
to kj...@conti-x.com, grpc.io
https://github.com/grpc/grpc-java/blob/master/README.md describes how to setup your build. The examples show how you implement a server. If your service is named "YourService" then you would implement the YourServiceGrpc.YourService interface.

I'm not quite sure what you mean by "compile the actual server."

On Tue, Oct 27, 2015 at 1:45 PM, <kj...@conti-x.com> wrote:
I'm having a lot of trouble figuring out how to compile a GRPC Java server. I looked all over the grpc.io website and closest thing I found was this: http://www.grpc.io/docs/#quick-start , where I run ../gradlew -PskipCodegen=true installDist to build, and ./build/install/grpc-examples/bin/hello-world-client to run the client. This all works, but only for the hello-world tutorial. I have no idea how to do this for my own client/server. I'm able to generate the client/server protobufs using the .proto file. I looked in their readme and Java tutorial and couldn't find out how to compile the actual server (and client) after I write them https://github.com/grpc/grpc-java/blob/master/examples/README.md  http://www.grpc.io/docs/tutorials/basic/java.html#try-it-out . Unless there's documentation im missing, does anyone know how to compile a server and client that implements the GRPC classes generated from the .proto file? I did spend a fair amount of time searching. Any advice is much appreciated, thanks.

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/c2790384-a07a-42ae-a48d-b24980744337%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

kj...@conti-x.com

unread,
Oct 27, 2015, 5:41:05 PM10/27/15
to grpc.io, kj...@conti-x.com
I created ___Server.java with the start() and main(), and created an inner class that implements the service and implements the methods defined in the interface. So i have all the protocol buffer generated .java files and the server right now. I just want to compile and run this server (through the terminal). What does it mean exactly by the below (where do i put this dependency)? I used gradle with the helloworld, so i'm assuming i can just use gradle with this new server. I'm new to gradle as well so sorry if this question was dumb

Or for Gradle, add to your dependencies:
compile 'io.grpc:grpc-all:0.9.0'

Eric Anderson

unread,
Oct 27, 2015, 6:19:40 PM10/27/15
to kj...@conti-x.com, grpc.io
On Tue, Oct 27, 2015 at 2:41 PM, <kj...@conti-x.com> wrote:
I created ___Server.java with the start() and main(), and created an inner class that implements the service and implements the methods defined in the interface. So i have all the protocol buffer generated .java files and the server right now.

Did you run protoc manually? If so, sorry, we would generally just hope the build plugin would do that.

I just want to compile and run this server (through the terminal). What does it mean exactly by the below (where do i put this dependency)? I used gradle with the helloworld, so i'm assuming i can just use gradle with this new server. I'm new to gradle as well so sorry if this question was dumb

Or for Gradle, add to your dependencies:
compile 'io.grpc:grpc-all:0.9.0'

Oh, we sort of expect that gRPC users already have a build system of choice. Maven and Gradle are common.

You might read one of these getting starteds to create the basic build file:

kj...@conti-x.com

unread,
Oct 28, 2015, 7:09:15 PM10/28/15
to grpc.io, kj...@conti-x.com
Thanks i'll take a look at the gradle doc. Do you know if it's possible, and if so, how would I put my java rpc server onto Amazon's elastic beanstalk? Gradle generates a binary i think, but beanstalk doesn't accept a binary.

kj...@conti-x.com

unread,
Oct 28, 2015, 7:12:41 PM10/28/15
to grpc.io, kj...@conti-x.com
Oh gradle generates a jar actually. Is it as simple as uploading the jar to amazon to put it on elastic beanstalk?

Kevin Ma

unread,
Oct 29, 2015, 2:40:12 PM10/29/15
to Eric Anderson, grpc.io
So i think my project is missing some of the grpc libraries at run time (io.grpc.ServerBuilder). It compiles properly when i do gradle build, but when i try to run the jar, im getting: NoClassDefFound for the ServerBuilder. This is my current build.gradle file: 

apply plugin: 'java'
dependencies {
compile 'io.grpc:grpc-all:0.9.0'
runtime 'io.grpc:grpc-all:0.9.0'
}

repositories {
mavenCentral()
mavenLocal()

}

//set main
jar {
    manifest {
        attributes 'Main-Class': 'src.main.java.CarServer'
    }
}

Am i missing something? I have runtime dependency set for the grpc libs, but I'm still getting NoClassDefFound. Thanks

kj...@conti-x.com

unread,
Oct 29, 2015, 2:41:16 PM10/29/15
to grpc.io, kj...@conti-x.com
So i think my project is missing some of the grpc libraries at run time (io.grpc.ServerBuilder). It compiles properly when i do gradle build, but when i try to run the jar, im getting: NoClassDefFound for the ServerBuilder. This is my current build.gradle file: 

apply plugin: 'java'
dependencies {
compile 'io.grpc:grpc-all:0.9.0'
runtime 'io.grpc:grpc-all:0.9.0'
}

repositories {
mavenCentral()
mavenLocal()

}

//set main
jar {
    manifest {
        attributes 'Main-Class': 'src.main.java.MyServer'
    }
}

Am i missing something? I have runtime dependency set for the grpc libs, but I'm still getting NoClassDefFound. Thanks

Eric Anderson

unread,
Nov 2, 2015, 3:06:31 PM11/2/15
to Kevin Ma, grpc.io
On Thu, Oct 29, 2015 at 11:40 AM, Kevin Ma <kj...@conti-x.com> wrote:
So i think my project is missing some of the grpc libraries at run time (io.grpc.ServerBuilder). It compiles properly when i do gradle build, but when i try to run the jar, im getting: NoClassDefFound for the ServerBuilder. This is my current build.gradle file: 
...
Am i missing something? I have runtime dependency set for the grpc libs, but I'm still getting NoClassDefFound. Thanks

The JAR only has your code in it. It sounds like you want to make a "fat" jar which includes all your dependencies. You can do something like this:

jar {
    from {
        configurations.compile.collect {
            it.isDirectory() ? it : zipTree(it)
        }
    }
}

Note that that isn't gRPC-specific; it's just working with Gradle. There may be alternatives, such as a quick Googling returned gradle-fatjar-plugin.
Reply all
Reply to author
Forward
0 new messages