在服务端(客户机)搭建matlab运行环境


1.下载MCR到客户机

https://cn.mathworks.com/products/compiler/matlab-runtime.html

注意对应的版本和位数,我的是matlab2012b x64就下载这个

可以将matlab布置在云服务器吗 matlab在服务器端运行_v8

二、安装下载下来的MCR,一路下一步安装就可以了,无需注册码。

检查 环境变量>>Path中是否已经有了C:\Program Files\MATLAB\MATLAB Compiler Runtime\v80\runtime\win64;

这项,有就是安装成功了。

三、配置java环境变量

注意:客户机配置的jdk版本一定要和编译matlab的java jar包时的版本一致,否则跑步起来。

1.在matlab中执行 version -java获取版本号:

>> version -java
ans =
Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode


2.网上下载 jdk1.6  x64版本,安装。

配置java环境变量,这一步搞java的是常识,自行配置。

在cmd中检验 java -version 和 javac -version 一致。


四、检验MCR环境

1.建议用matlab生成一个windows application test_demo.exe,有弹出窗口的那种。拷贝到客户机,用于测试环境是否搭建好。

拷贝到桌面,双击test_demo.exe看反应。

运气好的 新机器双击就能跑了,运气差的就各种问题。。。

跑起来的[检验MCR环境]OK,跑步起来往下看。

2.先将这个exe 复制到 D:\Program Files\MATLAB\MATLAB Compiler Runtime\v80\runtime\win64; 中,双击看反应;

一般都能跑起来,跑不起来就是MCR版本/位数跟生成环境对应不上。重装MCR后,重复这一步。

3.将这个exe复制到D盘根目录,打开CMD,执行D: 切换到D盘,执行 MemShieldStarter xxx.exe

看反应,cmd中会打印执行过程和报错提示。

CMD中执行MemShieldStarter xxx.exe通过,正常弹出matlab的窗口,就说明MCR环境没有问题了。

java调用报错问题继续往下看。


常见报错解决:

1.libut.dll or libmx.dll are not found 

 Fatal error loading library C:\Windows\system32\libmx.dll Error: 找不到指定的模块

找不到文件libmx.dll,百度好久没答案,拿个梯子一google就找到答案了。。。

Why do I receive errors saying native MCR dlls such as libut.dll or libmx.dll are not found when I run an application created by the MATLAB Compiler 4.16 (R2011b)?





This error may occur because a copy of the DLL in question resides somewhere on the system that is getting loaded before the expected version of of the DLL located in the MCR runtime directories.

The current application folder (where the executable is located) and OS system folders will be searched before the MCR runtime folder if they reside earlier on the system path. These usually contain the offending extra copy of the DLL.  Start by checking the path returned in the error message for the extra copy (it is likely but not necessary that the extra copy is located on this path).

To resolve this issue, make sure to remove any extra copies of the offending DLL files located on the machine.

The only correct versions of the MCR runtime DLLs should be in a subdirectory of the MCR installation, usually in the bin or runtime folders.


翻译过来就是:

这个错误可能会发生,因为这个DLL的副本存在于系统的某个地方,这个系统在MCR运行目录中,在预期的版本中加载了。
当前的应用程序文件夹(可执行文件的位置)和OS系统文件夹将在MCR运行时文件夹之前被搜索,如果它们位于系统路径的前面。这些通常包含DLL的额外副本。首先检查在错误消息中返回的路径,以获得额外的副本(很有可能,但是多余的副本位于此路径上是不必要的)。
要解决这个问题,请确保删除位于机器上的任何多余的DLL文件副本。
MCR运行时dll的唯一正确版本应该位于MCR安装的子目录中,通常在bin或运行时文件夹中。

不要在windows/system32中放 mclmcrrt8_0.dll 或 mclmcrrt9_0.dll等等,C#的com组件自动关联,先找到了windows/system32中的mclmcrrt8_0.dll,在找其他的dll找不到就报错。

删除windows/system32中的mclmcrrtX_X.dll即可。

2.Failed to find the library mclmcrrt8_0.dll 

找不到MCR运行环境。

检查系统环境变量path中是否引入,每次系统变量修改都要重新打开后执行命令cmd才生效,尝试 

[四、2.先将这个exe 复制到 D:\Program Files\MATLAB\MATLAB Compiler Runtime\v80\runtime\win64; 中,双击看反应;

一般都能跑起来,跑不起来就是MCR版本/位数跟生成环境对应不上。重装MCR后,重复这一步。]

3.mclmcrrt initlization failed

初始化失败

双击弹出窗口初始化失败的原因很多,建议在cmd中执行MemShieldStarter xxx.exe查看具体报错。

一般都是MCR环境问题,参考 问题2. 的答案。

4.java调用matlab生成的jar报错,报错只有一种

Exception in thread "main" java.lang.UnsatisfiedLinkError: Failed to find the required library mclmcrrt8_5.dll on java.library.path. This library is typically installed along with MATLAB or the MCR. Its absence may indicate an issue with that installation or the current path configuration. The MCR version that this component is trying to use is: 8.5.

环境不对找不到dll等等。

先确定 在桌面双击test_demo.exe可以正常跑起来。

跑不起来就是MCR环境还有问题,回去继续解决。

跑起来就是MCR环境OK了,java环境有问题。

java环境配置:java项目中设置jre版本,jre版本 要 与 matlab中 执行 version -java返回版本和位数一致。

可以将matlab布置在云服务器吗 matlab在服务器端运行_可以将matlab布置在云服务器吗_02

设置完可能会有缓存,把MJBuilderTest.java随便改一下保存重新编译在跑一次。

跑起来还是报错的话换个项目少的eclipse导入这个测试项目,在设置一遍jre跑,有可能是缓存影响。


总结:

matlab是做线性规划数据建模的专业工具,java能够直接调用的话还是省了很多在java实现算法的麻烦。

但是目前看MCR跟JRE的稳定性相比差了不少,如果不是在服务端调用matlab,在客户机器调用,而且客户机器很多的话,甚用,否则问题多多。