大家好!
请问Java里如何使用已经用C++写好的类呢?
有即用方法啊?
特别是在网站应用的时候!

解决方案 »

  1.   

    推荐使用 web service吧。参考http://www.javaeye.com/topic/233140
      

  2.   

    JNI
    C++还需要包装一套JNI的适配器
      

  3.   

    用 webservice可以解决不同语言之间的调用,只要提供服务接口就可以了,具体用什么语言实现不重要。
      

  4.   

    //李白饮酒问题
    public class Wire {
    public static void main(String[] args) {
    // 反推,最后一次遇花店
    double end = 0;
    // 倒数第二次为
    end = end + 1;
    for (int i = 0; i < 5; i++) {
    // 前9次为随机
    // Random ran = new Random();
    // System.out.println(ran.nextBoolean());
    end /= 2;
    end++;
    }
    System.out.println(end);
    }
    }
    打印答案:1.96875
    但是始终觉得有点问题.
      

  5.   

    把用C++写好的打包封装成动态库.dll文件, 在java中调用例如:
       public   class   GetData   {   
       public   native   String   GetSerial(String   S1);  //用native 说明后面的方法是其 它语言的方法,加载到本地方法,后面可以直接用
       public   native   String   GetIP(String   S1);      
       public   native   String   GetMAC(String   S1);   
       public   native   String   GetCorp(String   S1);   
       public   native   byte[]   baGetCorp(String   S1);   
        
          static   {   
              System.loadLibrary("Antiscan");       //Antiscan  c++的DLL文件名
          }   
        
          public   String   getcorp(String   S1)   {   
              String   bS   =   null;   
              byte   ba[]   =   baGetCorp(S1);     //这里调用dll里的方法   
              if   (ba   !=   null)   {   
                  bS   =   new   String(ba);   
              }   
              return   bS;   
          }   
        }  
      

  6.   

    JNI是java支持本地化的方法,能够用来调用C++的dll
      

  7.   

    在本网站中能够找到java调用C++的Dll的资料
      

  8.   

    用jni,
    发现一个比jni更方便的方法就是用jni基础之上的一个开源工具包jnative,非常方便的。