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

匿名 (未验证) 提交于 2019-12-03 08:46:08

问题:

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

回答1:

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.



回答2:

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



回答3:

What @laike9m suggested only partially worked for me. I definitely tried to do everything java/README.txt as @laike9m suggested. I had to install maven. I used brew to do that (brew install maven). I then built the protocol buffers java source using mvn package. The first time I tried that, it failed due to some obscure-ish error. I built the C++ code using ./configure && make. Next time I tried to build the java code using mvn package it worked. It put the resulting jar in a folder called target. I think went back to the examples area and was able to build the java example using make but I had to modify the Makefile by adding the -classpath... part below:

javac_middleman: AddPerson.java ListPeople.java protoc_middleman     javac -classpath .:../java/target/protobuf-java-2.6.1.jar:$$CLASSPATH AddPerson.java ListPeople.java com/example/tutorial/AddressBookProtos.java     @touch javac_middleman 


回答4:

Download protobuf.jar from below link and add jar file into libs folder.Its work for me.

https://code.google.com/archive/p/android-market-api/downloads



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!