把底层库打包进JAR的方法


[1/3] 背景

   最近用到 JavaCV做直播项目,在从github上下载了一个叫 RtmpRecoder的项目时,发现RtmpRecoder用到了通过JavaCV运用到ffmpeg,于是下载了JavaCV-bin (javacv-1.2-src.zip),解压后发现里面只有jar包,却没有发现任何底层库----没有底层库怎么调到ffmpeg那?

   带着这个疑问, 按照【Java CV与Android】在Android工程里配置JavaCV里介绍的,解压了其中一个jar文件ffmpeg-android-arm.jar,在目录javacv-bin/ffmpeg-android-arm/lib/armeabi下果然发现有一堆动态库。

   第一次见到JAR包中也可以包含底层库,很惊奇,就想知道是怎么做到的。就google搜索了下,发现可以运用Jar2Libjace技术生成。此外,JavaCPP技术能便捷的实现把底层库打包进JAR,能部分代替JNI技术(但是不能代替底层回调Java层)。

   在此,贴出具体方法,以备查阅。


[2/3] [转] Jace and Jar2Lib

Jar2Lib

Latest Version
1.1.1

Jar2Lib is a command line tool for generating C++ wrapper libraries around Java JAR files. It exposes the entire public Java API of the JAR in the corresponding C++ shared library, delegating to Java via JNI. The wrapping is performed using Jace.

We use Jar2Lib to generate the BF-CPP bindings for Bio-Formats, which we use in our WiscScan acquisition software.

Historical note: Jar2Lib was originally developed to integrate Bio-Formats with the Insight Toolkit, for use with the FARSIGHT project. However, we now have an dedicated inter-process solution for ITK integration instead which is easier to build from source, since it has no compile-time dependencies. Nonetheless, BF-CPP is still the recommended in-process solution for Bio-Formats native code integration.

Instructions

We recommend using Jar2Lib via the cppwrap-maven-plugin; see "Installation and usage" below.

If you prefer to use Jar2Lib directly from the command line outside Maven:

  1. Download the JARs linked above, as well as Apache Velocity 1.7 and its dependencies.
  2. With all necessary JARs in your current working directory, you can run Jar2Lib on the command line as follows:
$ java -cp '*' loci.jar2lib.Jar2Lib
Usage: java loci.jar2lib.Jar2Lib projectId projectName
  library.jar [library2.jar ...]
  [-conflicts conflicts.txt] [-header header.txt]
  [-extras cmake_extras.txt] [-output /path/to/output-project]
  [-core java_core_classes.txt
Language
Java
Installation and Usage

The easiest way to use Jar2Lib is via our cppwrap Maven plugin, which takes advantage of the Maven plug-in infrastructure to easily convert a Java library to C++ using Jar2Lib, without requiring any knowledge of Jar2Lib's workings or syntax. For example, it circumvents any need to download transitive dependencies.


更详细信息,请参考网址 https://loci.wisc.edu/software/jar2lib


[3/3] JavaCPP技术

JavaCPP 是一个开源库,它提供了在 Java 中高效访问本地 C++的方法。采用 JNI 技术实现,所以支持所有 Java 实现包括 Android 系统,Avian 和 RoboVM。

 3.1 JavaCPP Presets -- Prebuilt Java Bindings to C/C++ Libraries

These are part of a project that we call the JavaCPP Presets. Many coexist in the same GitHub repository, and all use JavaCPP to wrap predefined C/C++ libraries from open-source land. The bindings expose almost all of the relevant APIs and make them available in a portable and user-friendly fashion to any Java virtual machine (including Android), as if they were like any other normal Java libraries. We have presets for the following C/C++ libraries:

We will add more to this list as they are made, including those from outside the bytedeco/javacpp-presets repository.

3.2  Create New Presets

https://github.com/bytedeco/javacpp-presets/wiki/Create-New-Presets

1, [转]JavaCPP 技术使用经验总结

2, [转] 同一http://blog.csdn.net/chengkaizone/article/details/51087754


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值