Problems with using MATLAB Engine API for Java.

Hello,
I wish to use the MATLAB Engine API in order to handle data and use MATLAB functions, in conjunction with a Java Front-End for the purpose of a graphical user interface.
To begin with, I tried playing with some sample code. As a first step, I added the external library (`Engine.jar') to my project in Eclipse:
Next, I wrote the following `test code' in order to check for effective compilation:
package application;
import com.mathworks.engine.*;
public class Main {
public static void main(String[] args) throws Exception {
MatlabEngine eng = MatlabEngine.startMatlab();
eng.evalAsync("[X, Y] = meshgrid(-2:0.2:2);");
eng.evalAsync("Z = X .* exp(-X.^2 - Y.^2);");
Object[] Z = eng.getVariable("Z");
eng.close();
}
}
Following is the hierarchy of files in my Java project:
This leads to the following error message:
Exception in thread "main" java.lang.NoClassDefFoundError: com/mathworks/mvm/MvmTerminatedException
at application.Main.main(Main.java:7)
Caused by: java.lang.ClassNotFoundException: com.mathworks.mvm.MvmTerminatedException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
Can anyone suggest what I need to do differently here? Thanks in advance.

1 个评论

Solved this problem. Realized that I had added the wrong external jar file.

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Call MATLAB from Java 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by