Bored? Check out the Recent Activity on Siafoo Join Siafoo Now or Learn More

Protocol Buffers and Eclipse

over 10 years ago

One of my current projects involves sending data to a remote server using Google's Protocol Buffers. PBs let you define your data using a simple definition language which is then compiled into language specific (C++, Java, Python) load/store classes using the protocol compiler, protoc. This approach saves oodles of time but presents the slight annoyance of having to compile the .proto files whenever they change.

While Eclipse automagically compiles all of my Java code it doesn't support PBs "out of the box" (or in any way actually) so every time I modify the PB definition file I must compile it by hand. After the fourth instance of changing the .proto file "for the last time" it become obvious that a better solution was needed. Using a shell alias, make file, or an ant build script all seemed like poor solutions. Then it hit me, Eclipse must have support for external tooling.

Sure enough one could use an external program as a project Builder like this:

In the project properties dialog under Builders select New


then Program


which will open a dialog where you can enter information about the executable (eg. protoc) and the necessary arguments to run it.


In the Build Options tab make sure to select During auto builds (After clean is also a good idea I believe) and to also specify the resource to monitor, that is your .proto file by...


...clicking Specify Resource and finding your .proto file.



Make sure that your PB builder is at the very top of the builder list (or at least before the Java Builder) or else you'll always be compiling the previous version.

After 25 hair-pulling-minutes of trying to figure out WHY?! protoc doesn't like your arguments you will notice that it requires both the full path to the .proto file and the same path passed to the -I parameter.

That is all. Please enjoy Protocol Buffers and the Eclipse external builders responsibly.