Problems with using MATLAB Engine API for Java.

조회 수: 3 (최근 30일)
manan lalit
manan lalit 2017년 3월 2일
댓글: manan lalit 2017년 3월 2일
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
manan lalit
manan lalit 2017년 3월 2일
Solved this problem. Realized that I had added the wrong external jar file.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile 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