Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

package com.google.protobuf does not exist on OS X Maverick

I am on OS X Mavericks and starting learning about protobuf, i download the example from https://code.google.com/p/protobuf/downloads/list

I am successfully able to create the .java file from the proto but while compiling the existing java code using

make java, i am getting following error

com/example/tutorial/AddressBookProtos.java:91: package com.google.protobuf does not exist
      com.google.protobuf.GeneratedMessage
                         ^
com/example/tutorial/AddressBookProtos.java:12: package com.google.protobuf does not exist
      extends com.google.protobuf.MessageOrBuilder {
                                 ^
com/example/tutorial/AddressBookProtos.java:9: package com.google.protobuf does not exist
      com.google.protobuf.ExtensionRegistry registry) {
                         ^
com/example/tutorial/AddressBookProtos.java:2495: package com.google.protobuf.Descriptors does not exist
  private static com.google.protobuf.Descriptors.Descriptor
                                                ^
com/example/tutorial/AddressBookProtos.java:2498: package com.google.protobuf.GeneratedMessage does not exist
    com.google.protobuf.GeneratedMessage.FieldAccessorTable
....
....

Any resolution to this?

Thanks

like image 485
nothing_authentic Avatar asked Nov 24 '13 22:11

nothing_authentic


People also ask

Is protobuf required for gRPC?

Protobuf is the most commonly used IDL (Interface Definition Language) for gRPC. It's where you basically store your data and function contracts in the form of a proto file. As this is in the form of a contract, both the client and server need to have the same proto file.

Why did proto3 remove optional?

We have seen production issues caused by this multiple times and it's pretty much banned everywhere inside Google for anyone to add/remove required fields. For this reason we completely removed required fields in proto3. After the removal of "required", "optional" is just redundant so we removed "optional" as well.

Does Google use protobuf?

Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data – think XML, but smaller, faster, and simpler.

Is protobuf a library?

Protocol Buffers is a library from Google. It provides efficient and language-independent ways to serialize the data. It supports serialization and deserialization from languages like Java, Python, Go, Dart, etc.


2 Answers

You need to include libprotobuf.jar in your CLASSPATH. Follow the instructions under java/README.txt in the Protobuf source package to build it.

like image 35
Kenton Varda Avatar answered Nov 07 '22 01:11

Kenton Varda


Met the same problem and finally got it working. Here's what I did(using version 2.6.0) on OSX 10.9:

  1. Do everything java/README.txt tells you to

  2. if maven package succeed, you'll get a protobuf-java-2.6.0.jar under target folder, for me it's /Users/laike9m/Dev/protobuf-2.6.0/java/target/protobuf-java-2.6.0.jar.

  3. create ~/Library/Java/Extensions folder, note: this is platform specific operation, for OS other than OSX it should be $JAVA_HOME/lib/ext

  4. copy protobuf-java-2.6.0.jar to ~/Library/Java/Extensions

Then you should be able to run make java successfully.

like image 117
laike9m Avatar answered Nov 07 '22 03:11

laike9m