• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

gkubisa/jni-maven: Java JNI with Maven

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

gkubisa/jni-maven

开源软件地址(OpenSource Url):

https://github.com/gkubisa/jni-maven

开源编程语言(OpenSource Language):

Java 74.9%

开源软件介绍(OpenSource Introduction):

jni-maven

jni-maven is a sample project intended to be used as a template for Java applications using JNI.

Requirements

You'll need the following:

  • JDK
  • gcc
  • maven
  • ant
  • make

Usage

git clone https://github.com/gkubisa/jni-maven.git jni-maven
cd jni-maven
mvn package
java -cp target/jni-maven-1.0-SNAPSHOT.jar ie.agisoft.App

How it works

maven-antrun-plugin is added to the process-classes phase of the build. It is used to:

  • generate the C++ headers using javah. They are created in src/main/c++. I did not use javah ant target, because it assumes Sun JDK, while I'm using OpenJDK.
  • run make to build the native code

The Makefile compiles the native code from src/main/c++ into *.o files which are stored in target/c++. Then it runs the linker which produces a single *.so object stored in target/classes.

Because the *.so file is in target/classes, it's included in the final JAR file. This way the whole project produces a single artifact and can be easily used as a dependency by other Maven projects.

The final bit is the custom module loader LibraryLoader.loadLibrary, which extracts the native library from the jar into a temporary file and loads it - the standard System.loadLibrary cannot do it.

Limitations / possible improvements

  1. Native code build currently works only on Linux
  2. Only C++ is supported as the native language
  3. The paths in the Makefile are hard-coded. It would be nice to initialize them from Maven properties.

Patches welcome!

Credits

  1. http://docs.codehaus.org/display/MAVENUSER/Projects+With+JNI - jni-maven is a simplified implementation of the concept presented in this article
  2. http://code.google.com/p/jav8/ - LibraryLoader class in based on the code from this project (V8ScriptEngineFactory.java)



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
ZipCodeCore/Maven.TooLargeTooSmall发布时间:2022-08-17
下一篇:
gantsign/ansible-role-maven: Ansible role for installing Apache Maven发布时间:2022-08-17
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap