把底层库打包进JAR的方法

来源:互联网 发布:李炎恢php第一季课件 编辑:程序博客网 时间:2024/05/29 03:03


[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:
  • OpenCV – [sample usage] – More than 2500 optimized computer vision and machine learning algorithms
  • FFmpeg – [sample usage] – A complete, cross-platform solution to record, convert and stream audio and video
  • FlyCapture – [sample usage] – Image acquisition and camera control software
  • libdc1394 – [sample usage] – A high-level API for DCAM/IIDC cameras
  • OpenKinect – [sample usage] – Open source library to use the Xbox Kinect
  • videoInput – [sample usage] – A free Windows video capture library
  • ARToolKitPlus – [sample usage] – Marker-based augmented reality tracking library
  • Chilitags – [sample usage] – Robust fiducial markers for augmented reality and robotics
  • flandmark – [sample usage] – Open-source implementation of facial landmark detector
  • FFTW – [sample usage] – Fast computing of the discrete Fourier transform (DFT) in one or more dimensions
  • GSL – [sample usage] – The GNU Scientific Library, a numerical library for C and C++ programmers
  • LLVM – [sample usage] – A collection of modular and reusable compiler and toolchain technologies
  • Leptonica – [sample usage] – Software useful for image processing and image analysis applications
  • Tesseract – [sample usage] – Probably the most accurate open source OCR engine available
  • Caffe – [sample usage] – A fast open framework for deep learning
  • CUDA – [sample usage] – Arguably the most popular parallel computing platform for GPUs
  • MXNet – [sample usage] – Flexible and efficient library for deep learning
  • TensorFlow – [sample usage] – Computation using data flow graphs for scalable machine learning
  • Add here your favorite C/C++ library, for example: OpenNI, OpenMesh, PCL, etc. Read about how to do that.

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

官方网址 http://bytedeco.org/

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

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


0 0
原创粉丝点击