Thursday, May 23, 2013

Google protocol buffers



Running the examples in the source base have issues which are related to the classpath.
Somehow the readme does not state this issue clearly. 
This can result in a wasteful effort.


What I did to resolve the issue in order to run the examples successfully

1)
vmanohar@ubuntu:~/protobuf-2.5.0/java$ mvn install
vmanohar@ubuntu:~/protobuf-2.5.0/java$ mvn package

This generates the protobuf-java-2.5.0.jar in the target directory.
This has to be included in the javac -classpath and java -classpath commands.

2)
Edit the make file appropriately
Edit the make file in /home/vmanohar/protobuf-2.5.0/examples
 
javac_middleman: AddPerson.java ListPeople.java protoc_middleman
    javac -classpath /home/vmanohar/protobuf-2.5.0/java/target/protobuf-java-2.5.0.jar  AddPerson.java ListPeople.java com/example/tutorial/AddressBookProtos.java
    @touch javac_middleman
Add the highlighted -classpath.


3) Now run the make java command 


vmanohar@ubuntu:~/protobuf-2.5.0/examples$ make java

4)Compilation should be successful.
The make file auto-generates a script file add_person_java to ease out the quick-start but it actually ends up amplifying the efforts to find a fix. So do not use the script/ update the script.

I used the following command

java -classpath .:/home/vmanohar/protobuf-2.5.0/java/target/protobuf-java-2.5.0.jar  AddPerson addRecords

Here addRecords is a new file and hence the logic ends up generated logic ends up creating a new file.




--OUTPUT

addRecords: File not found.  Creating a new file.
Enter person ID: 123
Enter name: Peter
Enter email address (blank for none): xyz@gmail.com
Enter a phone number (or leave blank to finish): 234
Is this a mobile, home, or work phone? mobile
Enter a phone number (or leave blank to finish): 






 

No comments:

Post a Comment