当前位置: 代码迷 >> Ruby/Rails >> 在java中调用matlab程序时报错:java.lang.UnsatisfiedLinkError
  详细解决方案

在java中调用matlab程序时报错:java.lang.UnsatisfiedLinkError

热度:487   发布时间:2016-04-29 02:08:11.0
在java中调用matlab程序时报错:java.lang.UnsatisfiedLinkError:

最近几天尽跟matlab做斗争去了,好不容易有点结果了,拿着matlab的东西往java里一运行,直接报错了:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Failed to find the library mclmcrrt7_14.dll, required by MATLAB Builder JA, 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: 7.14.	at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration$ProxyLibraryDir.get(MCRConfiguration.java:167)	at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration$ProxyLibraryDir.<clinit>(MCRConfiguration.java:173)	at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration.getProxyLibraryDir(MCRConfiguration.java:178)	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:1549)	at operation.OperationMCRFactory.newInstance(OperationMCRFactory.java:49)	at operation.OperationMCRFactory.newInstance(OperationMCRFactory.java:60)	at operation.operation.<init>(operation.java:63)	at com.matlab4j.TestMatlab4j.main(TestMatlab4j.java:11)

?网上一查说是jre版本的问题。的确,我的matlab是64位的(因为我的系统是64位的), jre也是64位的,但我本地的jdk却是32位的(感觉有点怪怪的)。后来装了64位的jdk1.8,再执行项目就没有问题了。果然还是jre的问题啊。

?

关于怎么看jre的版本:

在matlab里面:在工具栏中找到Window----Common Window,然后在命令行中输入: version -java,回车,就可以看到java版本啦。我这里的版本是:Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode

?

查看本地java版本:这个很简单,cmd--(如果有设置环境变量,直接)java -version,回车。我这里的情况:

java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

?

也可以用java代码来查:

public class Test{    public static void main(String[] args){    	String arch = System.getProperty("sun.arch.data.model");    	System.out.println(arch);    }}

我以前是32位的,输出32。现在是64位的,输出64。

?

另外还有一个挺傻的问题:一个电脑上是可以装很多版本的jdk的,不需要写在以前的老版,因为新版本不会替换旧版本。我开始的时候还傻傻的以为会冲突,就把老版本的1.6给卸载了。后来某人说可以不用卸载直接装1.8个没有问题,考虑到好多项目用的都是1.6的环境,我又重新给装回来了,然后通过环境变量、MyEclipse的jre配置来控制用那个版本的。可能大家比我聪明,也可能有跟我一样滴,在这里写一下,跟我一样滴就别再犯傻了啊。

  相关解决方案