3

I am trying to use Protocol buffers in my project(web-app) based in Java. I downloaded zip Protocol Buffers 2.4.0a full source(C++,Java,Python) & Protocol Buffers 2.4.0 compiler-Windows binary.

I was able to build the .proto file and generate the required java classes for my project, using the protoc compiler. Then I included the java folder(protobuf-2.4.0a\java\src\main\java......) contained in the PB's downloaded zipped source code to my project's src directory. However as I can see in my IDE, some of its dependencies of those files are not yet resolved. and I was not able to deserialize the messages when i tried out, (I guess I was able to serialize, however).

Could you help me by letting me know what needs to be fixed ? Shouldnt I be instead putting a jar in my classpath rather than including the PB source code to my src folder?

(I didnt used maven anywhere to download anything. I do not know how to use maven)

4
  • "Some of its dependencies of those files" - could you give more details? Commented Mar 9, 2011 at 14:50
  • in the Descriptors.java file in the src code, there is an import statement: com.google.protobuf.DescriptorProtos.*; This package does not exist at all Commented Mar 9, 2011 at 15:07
  • Okay, I wondered whether that might be it... but I'm surprised you've managed to serialize anything then. Commented Mar 9, 2011 at 15:12
  • may be it didnt serialized but I got no errors while serializing(except when deserializing) and I was able to get the length of serialized bytes Commented Mar 9, 2011 at 15:26

1 Answer 1

3

You need to generate and build the Java code corresponding to the protobuf descriptors.

There are instructions for this near the bottom of the README.txt file in the java directory.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks Jon.. I could nt understand this syntax..if you could clarify a bit please..... 2) Invoke protoc to build DescriptorProtos.java: $ protoc --java_out=src/main/java -I../src \ ../src/google/protobuf/descriptor.proto
@aklin: The "$" represents the unix command prompt, and "\" is just a way of saying "continues on the next line". Just run protoc --java_out=src/main/java -I../src ../src/google/protobuf/descriptor.proto
Thanks Jon! your solution worked! but is it the proper way to include the src files of PB in my own code, rather cant I have a jar included in my classpath.?
@aklin: You don't have to - once the Java sources have been generated, you can build all of the PB code into your own jar file. It's just it doesn't come as a jar file.
Google protocol buffer is such a mess to install, getting all sorts of dependencies errors and it has really poor documentation at google site, at least they could add easy step by step installation steps... i have wasted more than six hours trying to add jar files, add source files, and getting errors, and unable to generate DesriptorProtos :/
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.