Failed to compile the protobuf java example

6,935 views
Skip to first unread message

David Portabella

unread,
Aug 31, 2010, 6:25:02 AM8/31/10
to Protocol Buffers
Hello,

I don't manage to compile the java example.
I do as follows (I've tried with OSX and Cygwin, with the exact same
results):

Download protobuf-2.3.0.zip from: http://code.google.com/p/protobuf/
unzip protobuf-2.3.0.zip
cd protobuf-2.3.0
./configure
# ./configure --disable-shared # in case of Cygwin
make
make check
make install

# note: compilation fails if the directory name contains blank spaces.

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
cd examples
make cpp
./add_person_cpp test.bin # this works.

make java
-- javac AddPerson.java ListPeople.java com/example/tutorial/
AddressBookProtos.java
-- com/example/tutorial/AddressBookProtos.java:12: package
com.google.protobuf does not exist

cp -r ../java/src/main/java/com/* com/ # I shouldn't need to do
this. i guess that the makefile should include the classpath.
make java
-- javac AddPerson.java ListPeople.java com/example/tutorial/
AddressBookProtos.java
-- ./com/google/protobuf/Descriptors.java:33: package
com.google.protobuf.DescriptorProtos does not exist

find .. -iname "*DescriptorProtos*"
-- nothing, this file does not exist.

Where should I get this class from
com.google.protobuf.DescriptorProtos?


Many thanks,
David

Kenton Varda

unread,
Aug 31, 2010, 7:51:10 PM8/31/10
to David Portabella, Protocol Buffers
Please read the readmes.  Running "make install" in the root directory installs the C++ libraries only.  You need to install the Java and Python versions separately by following the instructions in the corresponding directories.


--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.


Noah Easterly

unread,
Sep 21, 2010, 5:19:10 PM9/21/10
to Protocol Buffers
I installed the java libraries using `mvn install` in protobuf-2.3.0/
java, but still get the same errors when trying to do `make java` in
protobuf-2.3.0/examples. I've never used Maven before - is there
something I need to set up so javac knows where to look to find the
jarfile maven created (~/.m2/repository/com/google/protobuf/protobuf-
java/2.3.0/protobuf-java-2.3.0.jar)?

I've tried

% export CLASSPATH=~/.m2/repository
% make java

and

% export CLASSPATH=~/.m2/repository/com/google/protobuf/protobuf-java/
2.3.0/
% make java

But both seem to give the same error.

What should I be doing?


On Aug 31, 7:51 pm, Kenton Varda <ken...@google.com> wrote:
> Please read the readmes.  Running "make install" in the root directory
> installs the C++ libraries only.  You need to install the Java and Python
> versions separately by following the instructions in the corresponding
> directories.
>
> On Tue, Aug 31, 2010 at 3:25 AM, David Portabella <
>
> > protobuf+u...@googlegroups.com<protobuf%2Bunsu...@googlegroups.com>
> > .

Kenton Varda

unread,
Sep 21, 2010, 8:15:25 PM9/21/10
to Noah Easterly, Protocol Buffers
You need to list the .jar file itself in the CLASSPATH.  It's not enough to just list the directory that contains it.

To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.

Vivek kumar

unread,
Nov 8, 2016, 6:28:03 PM11/8/16
to Protocol Buffers, david.po...@gmail.com
ac3@ac3-Veriton-Series:~$ javac AddPerson.java -cp protobuf-java-3.0.0.jar

its shows error:


AddPerson.java:3: error: package com.example.tutorial.AddressBookProtos does not exist
import com.example.tutorial.AddressBookProtos.AddressBook;
                                             ^
AddPerson.java:4: error: package com.example.tutorial.AddressBookProtos does not exist
import com.example.tutorial.AddressBookProtos.Person;
                                             ^
AddPerson.java:15: error: cannot find symbol
  static Person PromptForAddress(BufferedReader stdin,
         ^
  symbol:   class Person
  location: class AddPerson
AddPerson.java:17: error: package Person does not exist
    Person.Builder person = Person.newBuilder();
          ^
AddPerson.java:17: error: cannot find symbol
    Person.Builder person = Person.newBuilder();
                            ^
  symbol:   variable Person
  location: class AddPerson
AddPerson.java:38: error: package Person.PhoneNumber does not exist
      Person.PhoneNumber.Builder phoneNumber =
                        ^
AddPerson.java:39: error: package Person does not exist
        Person.PhoneNumber.newBuilder().setNumber(number);
              ^
AddPerson.java:44: error: package Person does not exist
        phoneNumber.setType(Person.PhoneType.MOBILE);
                                  ^
AddPerson.java:46: error: package Person does not exist
        phoneNumber.setType(Person.PhoneType.HOME);
                                  ^
AddPerson.java:48: error: package Person does not exist
        phoneNumber.setType(Person.PhoneType.WORK);
                                  ^
AddPerson.java:68: error: package AddressBook does not exist
    AddressBook.Builder addressBook = AddressBook.newBuilder();
               ^
AddPerson.java:68: error: cannot find symbol
    AddressBook.Builder addressBook = AddressBook.newBuilder();
                                      ^
  symbol:   variable AddressBook
  location: class AddPerson
12 errors
 please help im new to protocol buffer

Adam Cozzette

unread,
Nov 9, 2016, 4:38:21 PM11/9/16
to Vivek kumar, Protocol Buffers, david.po...@gmail.com
That javac invocation is failing because it is not being given the generated code from the protobuf compiler (protoc). I would recommend building the Java examples by running "make java"; just make sure that protoc is on your PATH and that the protobuf JAR is in your CLASSPATH.

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+unsubscribe@googlegroups.com.

To post to this group, send email to prot...@googlegroups.com.

Vivek kumar

unread,
Nov 11, 2016, 12:43:23 AM11/11/16
to Protocol Buffers, vive...@gmail.com, david.po...@gmail.com
thanks a lot..
i have  missed : make java & and i have not set classpath and path as well..
now successfully compiled
thanks
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages