The missing bridge between Java and native C++ libraries
Java Other
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
ale Update version in the `pom.xml` files to 1.4.3-SNAPSHOT Jul 18, 2018
arpack-ng * Upgrade presets for MKL-DNN 0.16, ARPACK-NG 3.6.2, Tesseract 4.0.0… Aug 15, 2018
artoolkitplus Update version in the `pom.xml` files to 1.4.3-SNAPSHOT Jul 18, 2018
caffe * Upgrade presets for cuDNN 7.2 Aug 16, 2018
chilitags Update version in the `pom.xml` files to 1.4.3-SNAPSHOT Jul 18, 2018
ci * Upgrade presets for cuDNN 7.2 Aug 16, 2018
cminpack Update version in the `pom.xml` files to 1.4.3-SNAPSHOT Jul 18, 2018
cuda * Upgrade presets for cuDNN 7.2 Aug 16, 2018
ffmpeg * Upgrade presets for FFmpeg 4.0.2 and its dependencies Aug 10, 2018
fftw Update version in the `pom.xml` files to 1.4.3-SNAPSHOT Jul 18, 2018
flandmark Update version in the `pom.xml` files to 1.4.3-SNAPSHOT Jul 18, 2018
flycapture Update version in the `pom.xml` files to 1.4.3-SNAPSHOT Jul 18, 2018
gsl Update version in the `pom.xml` files to 1.4.3-SNAPSHOT Jul 18, 2018
hdf5 * Make MSBuild compile more efficiently on multiple processors (pull #… Aug 15, 2018
leptonica Add missing license files for OpenCV, FFmpeg, HDF5, and Leptonica Aug 3, 2018
libdc1394 Update version in the `pom.xml` files to 1.4.3-SNAPSHOT Jul 18, 2018
libfreenect Upgrade all Maven dependencies and plugins to latest versions Jul 28, 2018
libfreenect2 Update version in the `pom.xml` files to 1.4.3-SNAPSHOT Jul 18, 2018
libpostal Update version in the `pom.xml` files to 1.4.3-SNAPSHOT Jul 18, 2018
librealsense Update version in the `pom.xml` files to 1.4.3-SNAPSHOT Jul 18, 2018
liquidfun Update version in the `pom.xml` files to 1.4.3-SNAPSHOT Jul 18, 2018
llvm * Make MSBuild compile more efficiently on multiple processors (pull #… Aug 15, 2018
mkl-dnn * Bundle native resources (header files and import libraries) of MKL… Aug 17, 2018
mkl Update version in the `pom.xml` files to 1.4.3-SNAPSHOT Jul 18, 2018
mxnet * Upgrade presets for MKL-DNN 0.16, ARPACK-NG 3.6.2, Tesseract 4.0.0… Aug 15, 2018
onnx * Add presets for ONNX 1.2.2 (pull #547) Aug 4, 2018
openblas Update version in the `pom.xml` files to 1.4.3-SNAPSHOT Jul 18, 2018
opencv * Upgrade presets for cuDNN 7.2 Aug 16, 2018
platform * Upgrade presets for cuDNN 7.2 Aug 16, 2018
skia Update version in the `pom.xml` files to 1.4.3-SNAPSHOT Jul 18, 2018
systems Update version in the `pom.xml` files to 1.4.3-SNAPSHOT Jul 18, 2018
tensorflow * Enable Python API for TensorFlow build with Bazel (issue #602) Aug 18, 2018
tensorrt * Upgrade presets for cuDNN 7.2 Aug 16, 2018
tesseract Fix builds for MKL-DNN and Tesseract on Windows Aug 16, 2018
videoinput Update version in the `pom.xml` files to 1.4.3-SNAPSHOT Jul 18, 2018
.appveyor.yml Reenable Windows builds for TensorFlow on AppVeyor CI Jul 28, 2018
.gitignore * Introduce platform artifacts that depend on binaries for all avail… Oct 27, 2016
.travis.yml * Add presets for ONNX 1.2.2 (pull #547) Aug 4, 2018
CHANGELOG.md * Enable Python API for TensorFlow build with Bazel (issue #602) Aug 18, 2018
LICENSE.txt * Offer the Apache License, Version 2.0, as a new choice of license,… Jun 14, 2015
README.md * Upgrade presets for cuDNN 7.2 Aug 16, 2018
cppbuild.sh * Add presets for ONNX 1.2.2 (pull #547) Aug 4, 2018
pom.xml * Add presets for ONNX 1.2.2 (pull #547) Aug 4, 2018

README.md

JavaCPP Presets

Join the chat at https://gitter.im/bytedeco/javacpp Maven Central Sonatype Nexus (Snapshots) Travis CI AppVeyor

Introduction

The JavaCPP Presets module contains Java configuration and interface classes for widely used C/C++ libraries. The configuration files in the org.bytedeco.javacpp.presets package are used by the Parser to create from C/C++ header files the Java interface files targeting the org.bytedeco.javacpp package, which is turn are used by the Generator and the native C++ compiler to produce the required JNI libraries. Moreover, helper classes make their functionality easier to use on the Java platform, including Android.

Please refer to the wiki page for more information about how to create new presets. Since additional documentation is currently lacking, please also feel free to ask questions on the mailing list.

Downloads

JAR files containing binaries for all child modules and builds for all supported platforms (Android, iOS, Linux, Mac OS X, and Windows) can be obtained from the Maven Central Repository.

To install manually the JAR files, follow the instructions in the Manual Installation section below.

We can also have everything downloaded and installed automatically with:

  • Maven (inside the pom.xml file)
  <dependency>
    <groupId>org.bytedeco.javacpp-presets</groupId>
    <artifactId>${moduleName}-platform</artifactId>
    <version>${moduleVersion}-1.4.2</version>
  </dependency>
  • Gradle (inside the build.gradle file)
  dependencies {
    compile group: 'org.bytedeco.javacpp-presets', name: moduleName + '-platform', version: moduleVersion + '-1.4.2'
  }
  • Leiningen (inside the project.clj file)
  :dependencies [
    [~(symbol (str "org.bytedeco.javacpp-presets/" moduleName "-platform")) ~(str moduleVersion "-1.4.2")]
  ]
  • sbt (inside the build.sbt file)
  libraryDependencies += "org.bytedeco.javacpp-presets" % moduleName + "-platform" % moduleVersion + "-1.4.2"

where the moduleName and moduleVersion variables correspond to the desired module. This downloads binaries for all platforms, but to get binaries for only one platform we can set the javacpp.platform system property (via the -D command line option) to something like android-arm, linux-x86_64, macosx-x86_64, windows-x86_64, etc. Another option available for Scala users is sbt-javacpp.

Required Software

To use the JavaCPP Presets, you will need to download and install the following software:

Further, in the case of Android, the JavaCPP Presets also rely on:

Manual Installation

Simply put all the desired JAR files (opencv*.jar, ffmpeg*.jar, etc.), in addition to javacpp.jar, somewhere in your class path. The JAR files available as pre-built artifacts are meant to be used with JavaCPP. The binaries for Linux were built for CentOS 6 and 7, so they should work on most distributions currently in use. The ones for Android were compiled for ARMv7 processors featuring an FPU, so they will not work on ancient devices such as the HTC Magic or some others with an ARMv6 CPU. Here are some more specific instructions for common cases:

NetBeans (Java SE 7 or newer):

  1. In the Projects window, right-click the Libraries node of your project, and select "Add JAR/Folder...".
  2. Locate the JAR files, select them, and click OK.

Eclipse (Java SE 7 or newer):

  1. Navigate to Project > Properties > Java Build Path > Libraries and click "Add External JARs...".
  2. Locate the JAR files, select them, and click OK.

IntelliJ IDEA (Android 4.0 or newer):

  1. Follow the instructions on this page: http://developer.android.com/training/basics/firstapp/
  2. Copy all the JAR files into the app/libs subdirectory.
  3. Navigate to File > Project Structure > app > Dependencies, click +, and select "2 File dependency".
  4. Select all the JAR files from the libs subdirectory.

After that, we can access almost transparently the corresponding C/C++ APIs through the interface classes found in the org.bytedeco.javacpp package. Indeed, the Parser translates the code comments from the C/C++ header files into the Java interface files, (almost) ready to be consumed by Javadoc. However, since their translation still leaves to be desired, one may wish to refer to the original documentation pages. For instance, the ones for OpenCV and FFmpeg can be found online at:

Build Instructions

If the binary files available above are not enough for your needs, you might need to rebuild them from the source code. To this end, project files on the Java side were created as Maven modules. By default, the Maven build also installs the native libraries on the native C/C++ side with the cppbuild.sh scripts, but they can also be installed by other means.

Additionally, one can find on the wiki page additional information about the recommended build environments for the major platforms.

The Maven modules

The JavaCPP Presets depend on Maven, a powerful build system for Java, so before attempting a build, be sure to install and read up on:

Each child module in turn relies by default on the included cppbuild.sh scripts, explained below, to install its corresponding native libraries in the cppbuild subdirectory. To use native libraries already installed somewhere else on the system, other installation directories than cppbuild can also be specified either in the pom.xml files or in the .java configuration files. The following versions are supported:

Once everything installed and configured, simply execute

$ mvn install --projects .,opencv,ffmpeg,flycapture,libdc1394,libfreenect,videoinput,artoolkitplus,etc.

inside the directory containing the parent pom.xml file, by specifying only the desired child modules in the command, but without the leading period "." in the comma-separated list of projects, the parent poml.xml file itself might not get installed. Also specify -Djavacpp.cppbuild.skip as option to skip the execution of the cppbuild.sh scripts. Please refer to the comments inside the pom.xml file for further details. From the "platform" subdirectory, we can also install the "platform" artifacts with a similar command:

$ cd platform
$ mvn install --projects ../opencv/platform,../ffmpeg/platform,etc. -Djavacpp.platform.host

The cppbuild.sh scripts

Running the scripts allows us to install easily the native libraries on multiple platforms, but additional software is required:

With the above in working order, the scripts get launched automatically as part of the Maven build lifecycle, but we can also manually execute

$ ANDROID_NDK=/path/to/android-ndk/ bash cppbuild.sh [-platform <name>] <install | clean> [projects]

where possible platform names are: android-arm, android-x86, linux-x86, linux-x86_64, linux-armhf, linux-ppc64le macosx-x86_64, windows-x86, windows-x86_64, etc. (The ANDROID_NDK variable is required only for Android builds.) Please note that the scripts download source archives from appropriate sites as necessary.

To compile binaries for an Android device with no FPU, first make sure this is what you want. Without FPU, the performance of either OpenCV or FFmpeg is bound to be unacceptable. If you still wish to continue down that road, then replace "armeabi-v7a" by "armeabi" and "-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16" with "-march=armv5te -mtune=xscale -msoft-float", inside various files.

Although JavaCPP can pick up native libraries installed on the system, the scripts exist to facilitate the build process across multiple platforms. They also allow JavaCPP to copy the native libraries and load them at runtime from the JAR files created above by Maven, a useful feature for standalone applications or Java applets. Moreover, tricks such as the following work with JNLP:

    <resources os="Linux" arch="x86 i386 i486 i586 i686">
        <jar href="lib/opencv-linux-x86.jar"/>
        <jar href="lib/ffmpeg-linux-x86.jar"/>
    </resources>
    <resources os="Linux" arch="x86_64 amd64">
        <jar href="lib/opencv-linux-x86_64.jar"/>
        <jar href="lib/ffmpeg-linux-x86_64.jar"/>
    </resources>

Thanks to Jose Gómez for testing this out!

How Can I Help?

Contributions of any kind are highly welcome! At the moment, the Parser has limited capabilities, so I plan to improve it gradually to the point where it can successfully parse large C++ header files that are even more convoluted than the ones from OpenCV, Caffe, or TensorFlow, but the build system could also be improved. Consequently, I am looking for help especially with the five following tasks, in no particular order:

  • Setting up continuous integration, preferably free on the cloud (Travis CI?)
  • Improving the Parser (by using the presets for Clang?)
  • Providing builds for more platforms, as with linux-armhf for Raspberry Pi, etc.
  • Replacing the Bash/Maven build combo by something easier to use (Gradle?)
  • Adding new presets as child modules for other C/C++ libraries (Caffe2, OpenNI, OpenMesh, PCL, etc.)

To contribute, please fork and create pull requests, or post your suggestions as a new "issue". Thank you very much in advance for your contribution!


Project lead: Samuel Audet [samuel.audet at gmail.com](mailto:samuel.audet at gmail.com)
Developer site: https://github.com/bytedeco/javacpp-presets
Discussion group: http://groups.google.com/group/javacpp-project