`

使用 JunC++ion 创建JNI

    博客分类:
  • JAVA
阅读更多

      在java中创建jni,都是通过一些命令,创建一些基本文件,然后在VS C++中,创建工程,导入那些文件,比较繁琐,不容易管理,而且c++中出了异常的话,java也不好处理。基于以上原因,我们可以使用JunC++ ion来使得整个过程自动化。


JunC++ion 创建JNI过程
     首先将所有的native方法的class放入一个单独的java工程里,在ANT文件中,配置好,运行后,可以生成一个c++工程。接下来只需在xxxuserImpl文件中,做参数转换和调用native方法实现,最后编译,链接生成dll。在Java中,这些参数不使用java基本类型而使用包装类型为好。在参数转换时,就完全可以采用标准c++类型来处理了。JunC++ion对java的基本类型,采用c++做了重写。如:java.lang.String,重写为:Java::lang::string.

 

总结:快速创建C++工程,便于管理,可以异常控制等等。

 

 Here's what you would do in Java:

  • design a Java type that exposes the desired API to Java applications and internally uses native methods to delegate to the C++ side.
  • run the javah tool to generate C declarations for for the required native methods.
  • implement all the native methods in a combination of C, JNI, and your own C++ code.

Here's what the same development process looks like when you're using JunC++ion:

  • design a Java type that exposes the desired API to Java applications and internally uses native methods to delegate to the C++ side.
  • run the code generator to generate delegating implementations for the required native methods.
  • implement all the native methods in a combination of generated C++ proxy classes and your own C++ code. 

The obviousness of the answer depends on your familiarity with JNI and on the scale of your integration problem. JNI is typically considered a rather unattractive integration technology because it's so error-prone and hard to use. When you're implementing native methods using JNI, you rarely have the luxury of only using your own code in the implementation. Much more frequently, you need to access elements on the Java side or create Java instances as return values, forcing you to call back into Java via JNI. Coding JNI by hand is a shortcut to an unstable appliation because it's trivially easy (even for an experienced JNI developer) to leak references or make other mistakes that will eventually lead to a hard-to-debug application failure. If you add C++ with its ability to throw exceptions to the mix, you almost certainly have a catastrophe that's just waiting to happen because your Java process will not tolerate a C++ exception thrown from within a native method.

 

分享到:
评论

相关推荐

    JAVA转换C++的工具和代码2.0

    很多时候,在JAVA中有不错的实现,比如一个LIB,一个CLASS。很想把它转换为C++实现。在网上找了很久,需望能找到一个工具,自动化一下。可惜,我一直没有找到,今天顺手写了一个,给大家分享。。...

    junc:Java功能库

    junc-功能性Java ##背景在函数式编程中,开发人员通常坚持不变性的做法。 这些语言往往表现力很强,甚至语言的流控制元素也像函数一样返回值。 通常,只要您的程序停止按顺序处理代码,函数式编程和命令式编程就会...

    基于道路网的最短路径算法的研究与实现

    基于道路网的最短路径算法的研究与实现 很好的毕业设计资料哦

    JUnC - Java Underdeveloped Compiler-开源

    基本上,这是我们正在开发的教育性Java编译器-只是为了深入了解编译器的工作原理。 它不打算用于商业用途!! 它是用Java编写的,并使用ANTLR解析器生成器和扩展的字节码工程库

    Junc-cli:JuncDT的脚手架工具

    君克利 JuncDT的脚手架工具

    微通道法制备单分散液滴的研究进展 (2013年)

    对被动法T型(T-junc tion)、流动聚焦型(flow-focusing)和同轴环管型(co-flowing)3种微通道结构进行了说明,阐述了近年来这3种通道内两相动力学的研究进展,并对可大批量生成液滴的微流体芯片进行了介绍。同时对几种...

    激光对PIN结光电二极管热破坏机理的研究

    就高功率激光对PIN结光电二极管因热效应引起的硬破坏过程进行了理论和实验研究.提出激光的热效应与伴随等离子体扩展时向外喷溅形成的冲刷效应是导致硅光二极管被破坏的主要原因。得到了Q开关YAG激光与PIN结光电...

    硬盘安装助手 Leopard hd install helper v0.3

    硬盘安装助手 Leopard hd install helper v0.3 可以吧镜像文件(dmg, iso都可以,其它的没试过)刻录到硬盘的分区上,配上变色龙,就可以实现从硬盘安装系统(一般都能)。

    Chameleon Install 1577(变色龙)

    window环境下的,系统引导工具,第一启动项要设为光驱才可以进入,可引导系统安装。

    KeyRemap4MacBook.pkg

    这是mac系统修改键盘映射的一款工具软件,解压安装后在系统偏好设置那里找到。可以自己建立不同的映射关系。可以充当魔兽等游戏的改键工具,不过大部分都要自己去实现,网上有说明,所以这里只是提供工具的下载。...

Global site tag (gtag.js) - Google Analytics