I am trying to use Java protobuf stubs inside Matlab. I generated the Java stub and corresponding jar file in Eclipse. I then take the jar file and add it to the Matlab path. In Matlab I do the following:
import raven.aos.*;
import raven.aos.Messages.*;
image = Image.newBuilder();
At this point I get an error message that says:
??? Undefined variable "Image" or class "Image.newBuilder".
Error in ==> pub>pub.pub at 16
image = Image.newBuilder();
I have successfully been able to use the Java jar in a Java project using the exact same syntax. So this validates that my stub is correct. I have also successfully imported and used a different Java library, zmq.jar, in my Matlab project, so to a certain extent this verifies that I know how to import jar files properly into Matlab.
I’ve refrained from attaching the generated Java stub file since it is very long. I hope that someone can point out what I’m doing wrong with just the code that I’ve provided. If required, I will add the stub source.
Thanks in advance!
Because generated protocol buffer message classes are inner classes, you need to use Matlab’s javaMethod command to get to the static methods. Import statement will not work. Using your example:
http://www.mathworks.com/help/techdoc/ref/javamethod.html