【问题标题】:Unable to run Java code on MATLAB Runtime in Unix environment无法在 Unix 环境中的 MATLAB Runtime 上运行 Java 代码
【发布时间】:2018-07-18 08:28:59
【问题描述】:

将 matlab 函数导出到 java 包后。我尝试运行以下包含 MATLAB 运行时的代码 unix 环境。

import com.mathworks.toolbox.javabuilder.MWArray;
import com.mathworks.toolbox.javabuilder.MWCharArray;
import calibrationAPINew.Calibration;

public class CHIndexCalculation {
        public static void main(String[] args) {

              MWCharArray number1 = null;
              Object[] result = null;
              Calibration calibration = null;
              String data = "{\r\n" +
                        "\"tsId\" : \"121213\",\r\n" +
                        "\"datapoints\" : [0.1,0.2,0.3,0.4]\r\n" +
                        "}";

              try
              {
                 System.out.println("Input data: " + data);
                 number1 = new MWCharArray(data); // Array of Input to be sent to MATLAB Runtime
                 System.out.println("MWCharArray: " + number1);
                 calibration = new Calibration();
                 result = calibration.calibrationAPI(1,number1);

                 System.out.println("Output : " +  result[0]);
              }
              catch (Exception e)
              {
                System.out.println("Exception Occurred : " + e);
                 e.printStackTrace();
              }
              finally
              {
                 //MWArray.disposeArray(number1);
                 //MWArray.disposeArray(result);
                 //calibration.dispose();
              }

        }
}

我已经在 unix box 上安装了 matlabruntime 并使用 export 语句设置了环境变量

export LD_LIBRARY_PATH=matlabrt/v92/runtime/glnxa64:matlabrt/v92/bin/glnxa64:matlabrt/v92/sys/os/glnxa64:matlabrt/v92/sys/opengl/lib/glnxa64

现在当我尝试运行命令时(calibrationAPINew.jar 是从 MATLAB 导出的 jar 文件)

java -cp javabuilder.jar:calibrationAPINew.jar:. CHIndexCalculation

我得到以下异常

com.mathworks.toolbox.javabuilder.MWException: Undefined function 'pdist2mex' for input arguments of type 'double'.
        at com.mathworks.toolbox.javabuilder.internal.MWMCR.mclFeval(Native Method)
        at com.mathworks.toolbox.javabuilder.internal.MWMCR.access$600(MWMCR.java:31)
        at com.mathworks.toolbox.javabuilder.internal.MWMCR$6.mclFeval(MWMCR.java:882)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at com.mathworks.toolbox.javabuilder.internal.MWMCR$5.invoke(MWMCR.java:769)
        at com.sun.proxy.$Proxy0.mclFeval(Unknown Source)
        at com.mathworks.toolbox.javabuilder.internal.MWMCR.invoke(MWMCR.java:443)
        at calibrationAPINew.Calibration.calibrationAPI(Calibration.java:223)
        at CHIndexCalculation.main(CHIndexCalculation.java:24)

我知道这与 MATLAB 运行时有关,但我不知道是什么?相同的设置在 windows 环境下也能正常工作。

【问题讨论】:

    标签: java matlab matlab-deployment matlab-compiler


    【解决方案1】:

    我认为 matlab 程序使用了一些已经为 windows 编译的 mexfile,因此它在 windows 上运行完美。由于 mexfile 已经可用,它将在 Windows 上完美运行。但是,当您的脚本无法为 linux 找到相应的 mexfile 时,它​​会失败或尝试使用 jar 包中未包含的函数“pdist2mex”为 linux 编译源文件。在 windows 中不需要此函数,因此它可以工作美好的。如果是这种情况,那么您可以从 matlab 将函数“pdist2mex”添加到您的 jar 中,或者您应该使用 matlab 手动将源代码编译为 linux 兼容的 mex 文件,然后尝试重新打包它,然后 matlab 会自动包装相应​​的 mex 文件到罐子里

    【讨论】:

    • 我会试试的
    猜你喜欢
    • 2019-02-19
    • 2013-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-24
    • 2014-07-13
    • 2010-09-25
    相关资源
    最近更新 更多