我现在想做一个java调用matlab的应用,最新的matlab2007提供一个组件:builder   for   java,可以把matlab函数打包成.jar,供java调用, 
        现在的情况是,我的一个朋友用matlab2007自带的例子(MagicSquareExample)给我做了一个magicsquare.jar包,我本机没有安装matlab,我是用myeclipse6.0开发的,用到的matlab的包就两个:magicsquare.jar和javabuilder.jar,调用matlab的例子也是他自带的,所以代码方面应该不会有什么问题, 
        但是我执行以后报错了:Exception   in   thread   "main"   java.lang.UnsatisfiedLinkError:   no   nativemcl77   in   java.library.path 
        UnsatisfiedLinkError的错误是:如果   Java   Virtual   Machine   不能找到被声明为   native   类型的方法的本地语言的定义时抛出该类的实例。no   nativemcl77   in   java.library.path   这个错误就不知道怎么回事了。 
        我在网上已经查了2天了,没有这方面的错误,然后我怀疑是不是还有什么matlab的包没有加进来,后来发现matlab下面有一个叫nativemc177.dll的文件,于是我强行的把这个文件拷到了window/system32/下面,结果程序报了另外一个错误: 
Exception   in   thread   "main"   java.lang.UnsatisfiedLinkError:   C:\WINDOWS\system32\nativemcl77.dll:   ?0?7?0?7?0?7?0?3?0?8?0?7???0?0?0?4???0?3?0?1?0?0???0?3?0?9?0?5?0?2?0?5?0?1?0?8?0?7???0?0?0?4???ā0?2?0?5?0?4?0?0?0?9?0?4?0?3?0?5?0?0?0?1?0?4??0?5?0?4?0?8?0?7???0?0?0?4???0?7?0?7?0?2?1?5~?0?8?0?9?0?5?0?9?0?0?0?2?0?2?0?8?0?0?7?3 
at   java.lang.ClassLoader$NativeLibrary.load(Native   Method) 
at   java.lang.ClassLoader.loadLibrary0(Unknown   Source) 
at   java.lang.ClassLoader.loadLibrary(Unknown   Source) 
at   java.lang.Runtime.loadLibrary0(Unknown   Source) 
at   java.lang.System.loadLibrary(Unknown   Source) 
at   com.mathworks.toolbox.javabuilder.MWMCR. <clinit> (MWMCR.java:1417) 
at   com.mathworks.toolbox.javabuilder.MWUtil.GetUnknownClassID(MWUtil.java:1566) 
at   com.mathworks.toolbox.javabuilder.MWClassID. <clinit> (MWClassID.java:39) 
at   com.mathworks.toolbox.javabuilder.MWBuiltinArray. <init> (MWBuiltinArray.java:37) 
at   com.mathworks.toolbox.javabuilder.MWEmptyArray. <init> (MWEmptyArray.java:26) 
at   com.mathworks.toolbox.javabuilder.MWEmptyArray. <clinit> (MWEmptyArray.java:33) 
at   com.mathworks.toolbox.javabuilder.MWArray. <clinit> (MWArray.java:23) 
at   computer.service.getmagic.main(getmagic.java:35)         我实在找不到原因了,这两天正在到处下载matlab2007,看是不是没有安装的原因,但是据官方的介绍,不用安装也能调用阿,希望各位高手能帮组我找到问题的答案,非常非常感谢了!!!

解决方案 »

  1.   

    应该是所依赖的东西不全。java.lang.ClassLoader$NativeLibrary.load(Native       Method)   
    而且还是jni的东西
      

  2.   

       那是什么原因导致的呢,根据matlab官方的说法,我不用安装matlab2007就能调用它生成的jar的,在我没有把nativemc117.dll放到windows/system32下面的时候,提示的错误不一样,是不是因为nativemc117.dll还有依赖的东西我没有放进去呢?那这样看来的话,我还是得安装matlab2007才能解决问题了?
      

  3.   

    终于解决了 相当不容易啊,我把经验跟大家分享一下,希望朋友们少走弯路1.没有安装matlab2007之前,程序报错:
    Exception   in   thread   "main"   java.lang.UnsatisfiedLinkError:   C:\WINDOWS\system32\nativemcl77.dll
    我查找资料发现,如果不安装matlab,则必须要安装MATLAB Component Run-time(MCR),
    2.安装了matlab2007以后,程序还是报了一个错:
    ???   Undefined   function   or   variable   'matlabrc'. 
    Exception:   com.mathworks.toolbox.javabuilder.MWException:   An   error   occurred   while   initializing   the   component.
    我不知道这个错误的原因是什么,但是我通过以下方法解决了这个问题--第一,下载jdk1.6(和matlab2007的jdk版本一致),然后把环境变量搭好,主要是java_home和path(java_home是一定要建的,由于我用的是eclipse,所以path无所谓了),第二,新建一个系统用户(因为我当前的这个用户是用中文命名的),不要用中文命名,然后用这个用户登录,运行程序,成功了!最后再说一下,我就是因为中文用户的原因,好几天都没有调通,所以matlab的相关目录最好是不要有空格和中文,特别是不要有中文
      

  4.   

    通MATLAB Builder for Java返回数据怎么将其矩阵转换为java的数组啊,谢谢,我看到C#用的是以下方法 :
    用于将matlab的返回值矩阵传递到C#规范的矩阵是:MWArray[] ResOut = null; //用于值输出的matlab矩阵ResOut=GTN.GetMatchNo(1,MainAdd, ModelAdd, FName.GTM(), Vaval);MWNumericArray temp = (MWNumericArray)ResOut[0]; //矩阵转换Array  netInterfaceMatrix = temp.ToArray(MWArrayComponent.Real); //c#规范的矩阵double[,] location = (double[,])netInterfaceMatrix; //变态的强制类型转换
      

  5.   

    我也在做Matlab for Java,按照帮助文档做但是还是出现问题。以Matlab中的magic例子为例:      前面的设置应该没问题,JDK的环境也没问题。getmagic的代码如下:
    /* getmagic.java
     * This file is used as an example for the MATLAB
     * Builder JA product.
    * Copyright 2001-2006 The MathWorks, Inc.
     */
    /* Necessary package imports */
    import com.mathworks.toolbox.javabuilder.*;
    import magicsquare.*;
    /* getmagic class computes a magic square of order N. The
     * positive integer N is passed on the command line.
     */
    public class Getmagic 
    {
       public static void main(String[] args)
       {
          MWNumericArray n = null;   /* Stores input value */
          Object[] result = null;    /* Stores the result */
          magic theMagic = null;     /* Stores magic class instance */
          try
          {
             /* If no input, exit */
             if (args.length == 0)
             {
                System.out.println("Error: must input a positive integer");
                return;
             }
             /* Convert and print input value*/
             n = new MWNumericArray(Double.valueOf(args[0]),MWClassID.DOUBLE);
             System.out.println("Magic square of order " + n.toString());
             /* Create new magic object */
             theMagic = new magic();
             
             /* Compute magic square and print result */
             result = theMagic.makesqr(1,n);
             System.out.println(result[0]);
          }
          catch (Exception e)
          {
             System.out.println("Exception: " + e.toString());
          }
          finally
          { /* Free native resources */
             MWArray.disposeArray(n);
             MWArray.disposeArray(result);
             if (theMagic != null)
                theMagic.dispose();
          }
       }
    }
    结果运行的错误就只有一个就是:
    [color=#FF0000]Exception in thread "main" java.lang.Error: 无法解析的编译问题:
     类型 magic 中的方法 makesqr(int, Object[])对于参数(int, MWNumericArray)不适用
     at src.Getmagic.main(Getmagic.java:39)
    一直找不到解决的方法,还望高手指点指点,在下十分感激,麻烦您了[/color]
      

  6.   

     1::::----/*if (args.length == 0) 
                 { 
                System.out.println("Error: must input a positive integer"); 
                return; */
    2 :::---args[0]  =10 ;ok了