我正在尝试使用JA Builder从Java执行MATLAB函数。
我遵循MATLAB JA Builder帮助文档 - HelloWorld和MagicSquare示例,每次都会收到以下堆栈跟踪:
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration.getProxyLibraryDir(MCRConfiguration.java:163)
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration$MCRRoot.get(MCRConfiguration.java:77)
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration$MCRRoot.<clinit>(MCRConfiguration.java:87)
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration.getMCRRoot(MCRConfiguration.java:92)
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration$ModuleDir.<clinit>(MCRConfiguration.java:66)
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration.getModuleDir(MCRConfiguration.java:71)
at com.mathworks.toolbox.javabuilder.internal.MWMCR.<clinit>(MWMCR.java:1573)
at com.mathworks.toolbox.javabuilder.MWUtil.GetUnknownClassID(MWUtil.java:727)
at com.mathworks.toolbox.javabuilder.MWClassID.<clinit>(MWClassID.java:41)
at getmagic.main(getmagic.java:36)
Caused by: java.lang.NullPointerException
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration$ProxyLibraryDir.get(MCRConfiguration.java:143)
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration$ProxyLibraryDir.<clinit>(MCRConfiguration.java:158)
... 10 more
getmagic.java中的第36行是:
n = new MWNumericArray(Double.valueOf(args[0]), MWClassID.DOUBLE);
我需要包含另一个JAR或一组配置文件吗?该程序目前引用了javabuilder.jar和MATLAB中编译的magicsquare.jar,如MATLAB JA Builder帮助文档中所述。
有什么想法?感谢
答案 0 :(得分:2)
您需要配置以下环境变量:
LD_LIBRARY_PATH
XAPPLRESDIR
安装MCR时,安装程序会告诉您所需的值(取决于您的mcrroot,安装MCR的目录)。例如/usr/local/MATLAB/
设置
export XAPPLRESDIR=/usr/local/MATLAB/MATLAB_Compiler_Runtime/v81/X11/app-defaults
答案 1 :(得分:1)
此设置适用于Linux:
export LD_LIBRARY_PATH=/usr/lib/matlab-8.6/runtime/glnxa64 \
/usr/lib/matlab-8.6/bin/glnxa64 \
/usr/lib/matlab-8.6/sys/os/glnxa64 \
/usr/lib/matlab-8.6/sys/opengl/lib/glnxa64
您可以在http://www.mathworks.com/help/compiler_sdk/java/mcr-path-settings-for-run-time-deployment.html
找到其他操作系统的说明