Problems with using MATLAB Engine API for Java.

3 views (last 30 days)
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 Comment
manan lalit
manan lalit on 2 Mar 2017
Solved this problem. Realized that I had added the wrong external jar file.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!