I have a file xxx.proto
. I downloaded the protobuf compiler and installed it. Then I issued this command
protoc --java_out=./ xxx.proto
and it generated my xxx.java
Now I want to compile this file into a class file which I can use with Scala.
javac xxx.java
Which gives me this error
xxx.java:7: package com.google.protobuf does not exist
com.google.protobuf.ExtensionRegistry registry) {
^
xxx.java:12450: package com.google.protobuf.Descriptors does not exist
private static com.google.protobuf.Descriptors.Descriptor
^
xxx.java:12453: package com.google.protobuf.GeneratedMessage does not exist
com.google.protobuf.GeneratedMessage.FieldAccessorTable
...
...
...
100 errors
Now I guessed, it doesnt have the package.
So I copied the class files of package com.google.protobuf into the same folder where xxx.java exists. Note - I didnt compile this package. I downloaded the jar from another extension which had the jar files. So I extracted them. Now my current path where xxx.java resides has com/google/protobuf/ *.class of protobuf library.
I issued the javac command again.
This time I got a different set of errors -
xxx.java:10: cannot find symbol
symbol : class MessageOrBuilder
location: package com.google.protobuf
extends com.google.protobuf.MessageOrBuilder {
^
xxx.java:215: cannot find symbol
symbol : class MessageOrBuilder
location: package com.google.protobuf
extends com.google.protobuf.MessageOrBuilder {
^
xxx.java:608: cannot find symbol
symbol : class MessageOrBuilder
location: package com.google.protobuf
extends com.google.protobuf.MessageOrBuilder {
^
xxx.java:1017: cannot find symbol
symbol : class MessageOrBuilder
location: package com.google.protobuf
extends com.google.protobuf.MessageOrBuilder {
..... 100 errors
I even tried to compile the source files which came with google protobufs. The generated java classes are giving the same errors.
Any ideas what to do ??
Answer
Okay. Thanks everyone.
The main problem is that protocol buffers compiler package from google doesnt by default create the java library. I assumed that it does and installs it. It actually does if you are running Maven. But i didnt have maven
So i compiled the code in /java/src
and used the jar.
^
One can install the protobuf jar file using the ubuntu a
This will copy the protobuf-java-2.4.1.jar under /usr/share/java/
Hope this helps
You may need to use version 2.4.1 (or 2.4+, at least) of the protobuf kit, including making sure that you update protoc (the protobuf compiler) and recompile your proto definition using the new protoc. (In other words, everything has to be the same version:
One I got everything synched, I began to move forward with a Clojure project I'm looking at. You may be encountering the same version skew problem.
you can download protoc.exe (new release) from>>.
in your *.proto file you correctly config
You are new to Java, right?
What is missing is the java library file (extension .jar) for protobuf. It has to be in the "classpath" for the java compiler and the java runtime. protoc generates your classes, but it depends on the protobuf library.
At runtime
When compiling, you need to have protobuf lib on your classpath. All those missing packages and classes are from protobuf lib.
Find protobuf jar and use