简体   繁体   English

在Matlab中导入Java类

[英]Importing java classes in Matlab

I have generated some Java classes from a proto file. 我已经从一个原始文件中生成了一些Java类。 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. 只是为了确保我没有犯错误:我首先使用protoc编译了proto文件,然后使用javac编译了生成的java文件。

I am trying to import the classes I generated in Matlab, but I kept getting the error: 我正在尝试导入在Matlab中生成的类,但是我一直收到错误消息:

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. 我在Matlab中修改了classpath.txt,添加了包含Java类的目录和jar文件本身的路径。 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. 我检查了一下,相信我用来编译Java类的Java版本与Matlab使用的版本相同。

Any idea? 任何想法? I do not manage to make sense of it.. :( 我没有弄懂它.. :(

Thanks! 谢谢!

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. 当类文件与嵌入式JVM不兼容时,MATLAB会误导性地产生No class MyClass can be located on the Java class path错误。 Make sure the Java classfiles you're trying to use do not target a newer JVM. 确保您尝试使用的Java类文件不针对较新的JVM。 You can use version -java to check MATLAB's JVM version. 您可以使用version -java来检查MATLAB的JVM版本。

R2007b: R2007b:

>> version -java

ans =

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

R2014b-Prerelease: 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. 如果您的类文件是使用较新的JDK编译的,则需要重新编译它们。 You can either use an older, compatible JDK; 您可以使用较旧的兼容JDK。 or you can use your newer JDK but run javac with the -source , -target , and -bootclasspath options to target the older MATLAB JVM. 或者您可以使用较新的JDK,但可以使用带有-source-target-bootclasspath选项的javac来定位较旧的MATLAB JVM。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM