Have been trying to install Protocol Buffers compiler and java runtime installation, but I'm getting an error when compiling the java classes. I downloaded:
protoc-3.2.0rc2-linux-x86_64.zip (although it says the version is 2.6.1)
protobuf-java-3.2.0rc2.zip
The file structure looks like this:
So assuming that's all fine, I typed in:
protoc --java_out=src/main/java -I../src \../src/google/protobuf/descriptor.proto
So protoc seems to be working fine. But then I kept getting errors like these until I commented them out (not sure if that is a problem?):
google/protobuf/descriptor.proto:443:3: Expected "required", "optional", or "repeated".
google/protobuf/descriptor.proto:443:12: Expected field name.
google/protobuf/descriptor.proto:541:3: Expected "required", "optional", or "repeated".
google/protobuf/descriptor.proto:541:12: Expected field name.
But when I try compiling all the java classes, I just keep getting an error saying:
Descriptors.java:1175: error: cannot find symbol
return FieldDescriptorProto.Type.forNumber(ordinal() + 1);
Any ideas on how to solve the problem? Can't see why it shouldn't compile. Tried looking on Google's page but nothing comes up on this.
Aware I sound a bit clueless although I've never really used libraries like protobuf from Github before so this is all new to me!
EDIT: Hi all, this issue was resolved with exactly the same file structure. I uninstalled protoc2.6.1, set my $JAVA_HOME and $PATH variables (you should store them too rather than having to export them every time), installed maven (properly).
All is well! Everything compiled without a hitch. Thanks to the responder!
protoc-3.2.0rc2-linux-x86_64.zip (although it says the version is 2.6.1)
This is the problem -- you are somehow using protoc 2.6.1 and not 3.2.0. This could be because protoc 2.6.1 was already installed on your system, and somehow it is taking precedence over 3.2.0. If you look at the errors in descriptor.proto, you'll notice they happen on the reserved
keyword, which is new; 2.6.1 didn't support it.
It's important to use exactly the same version of protoc as the Java runtime library, otherwise the generated code may not compile correctly, or may compile but not run correctly.