I have a myprotofile.proto file that looks like this
package PBPackage;
message SomeMessage {
required double someItem = 1;
}
I build it like this (I’m on linux)
JAVADIR=../../MyJarFile.jar
protoc -I=. --java_out=${JAVADIR} myprotofile.proto
My Java program, Program.java, looks like this
import PBPackage.SomeMessage;
public class Program {
public static void main( String[] args ){
System.out.println( "this is my program" );
}
}
I try to build Program.java like this
javac -cp .:MyJarFile.jar Program.java
But I always get this error:
Program.java:1 error cannot find symbol
import PBPackage.SomeMessage;
^
symbol: class SomeMessage
location: package PBPackage
What am I doing wrong?
Finally, please don’t tell me to use some overly complicated build system like ant or maven.
Most probably your JAR file contains this class in different package than you expect it.
There are two options you can use in your protobuf definition file to explicitly specify package and class name for generated code:
Please check this tutorial for more information.