javacpp
The missing bridge between Java and native C++
JavaCPP is a Java library that lets Java programs call code written in C++. Java and C++ are two different programming languages, and normally they cannot talk to each other directly. JavaCPP acts as a bridge, translating calls between them so that a Java application can use a C++ library as if it were a native part of the Java ecosystem.
The need for this kind of bridge arises frequently in areas like computer vision, machine learning, and multimedia processing, where many high-performance libraries are written in C++. JavaCPP has already been used to wrap well-known C++ libraries including OpenCV (image processing), FFmpeg (video encoding), TensorFlow, and CUDA (GPU computing), among others. Those wrapped versions are available as a companion project called JavaCPP Presets.
Under the hood, JavaCPP uses a standard Java mechanism called JNI (Java Native Interface) to communicate with native code. What JavaCPP adds on top of JNI is automatic generation of the connector code, so you do not have to write the tedious glue yourself. It handles a wide range of C++ features that are difficult to bridge, including templates, operator overloading, function pointers, virtual functions, inheritance, and memory management through shared pointers.
To use JavaCPP in a project, you add it as a dependency through Maven, Gradle, or another standard Java build tool. It requires a Java installation (version 8 or newer) and a C++ compiler on the same machine, because some compilation happens locally when building the native bindings. It works on Linux, macOS, and Windows, and also supports Android.
The project is available on Maven Central, which means it can be added to any Java project with a single dependency declaration. Documentation and examples are provided through a wiki, and community support is available via a mailing list and GitHub Discussions.