1

I have generated some Java classes from a proto file. Just to be sure I did not make mistakes: I first compiled the proto file using protoc and then compiled the generated java file using javac.

I am trying to import the classes I generated in Matlab, but I kept getting the error:

Error using javaMethod No class MyClass can be located on the Java class path

I modified the classpath.txt in Matlab, adding both the directory containing the java classes and the path to the jar file itself. I checked and I believe that the java version I am using to compile the java classes is the same as the one Matlab uses.

Any idea? I do not manage to make sense of it.. :(

Thanks!

1 Answer 1

1

MATLAB misleadingly produces the No class MyClass can be located on the Java class path error when the classfiles are not compatible with the embedded JVM. Make sure the Java classfiles you're trying to use do not target a newer JVM. You can use version -java to check MATLAB's JVM version.

R2007b:

>> version -java

ans =

Java 1.6.0 with Sun Microsystems Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode

R2014b-Prerelease:

>> version -java

ans =

Java 1.7.0_11-b21 with Oracle Corporation Java HotSpot(TM) Client VM mixed mode

If your classfiles were compiled with a newer JDK, you'll need to recompile them. You can either use an older, compatible JDK; or you can use your newer JDK but run javac with the -source, -target, and -bootclasspath options to target the older MATLAB JVM.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks a lot for your answer. That's the java version running on Matlab: Java 1.6.0_65-b14-462-11M4609 with Apple Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode and this is the same I used to compile the java files (java -version from terminal gave the same result)
It is the same version apparently.
That's good news. Double-check by running javac -version (instead of java -version), just in case the default JRE and JDK don't match.
I assume you already restarted MATLAB, and when you type javaclasspath on the MATLAB console, the directory or jarfile containing your Java classes is listed, correct?
yes, it is listed there and I restarted Matlab after any change I made.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.