Monday, October 28, 2013

on Leave a Comment

Setting up Protocol Buffers in Java

If you are starting to evaluate protocol buffers as a means of executing remote procedure calls in your application then you no doubt found your way to Google's getting started page. The first step after downloading the project is to install the compiler.

The downloaded project contains a readme file that will go over the basics of the install. Once you have the protobuf compiler up and running you are lead to believe that everything is good to go. The first thing I tried at this point was creating a new project and implementing the Java tutorial.


What is missing from the tutorial is exactly how the code should be imported into the project. For the sake of brevity (and just to see my tutorial code run) I copied the files under java/src into my project directory. When I went to run the project after importing the source files I still seemed to be missing one of the required source files.



It turns out that there is a step missing from the documentation. At this point I was missing the class "DescriptorProtos". It turns out that this class is itself generated from a .protos file called descriptor.proto. That .proto file is found under the google/protobuf/compiler directory in the source project. You simply need to execute the following command from the java directory and then copy the generated class into your project source.


Powered by Blogger.