Demonstrates the basics of OpenNI2 usage


Install gradle and Java


sudo apt install openjdk-11-jdk
sudo apt install gradle


Install JDK, Gradle and Visual Studio (we use VS2019).

Create new Java Project by gradle

  • Create new folder. In terminal, use gradle to initialize this project folder. Select application for type and Java for implementation language. Leave default for the rest.

gradle init

Select type of project to generate:
  1: basic
  2: application
  3: library
  4: Gradle plugin
Enter selection (default: basic) [1..4] 2

Select implementation language:
  1: C++
  2: Groovy
  3: Java
  4: Kotlin
  5: Swift
Enter selection (default: Java) [1..5] 3

Select build script DSL:
  1: Groovy
  2: Kotlin
Enter selection (default: Groovy) [1..2]

Select test framework:
  1: JUnit 4
  2: TestNG
  3: Spock
  4: JUnit Jupiter
Enter selection (default: JUnit 4) [1..4]

Project name (default: project_setup):
Source package (default: project_setup):
  • You will have a basic project structure looks like below

  • Now, create a new folder libs in this project. Copy org.openni.jar from OpenNI2 SDK into libs folder

  • Edit build.gradle, add implementation files('libs/org.openni.jar') in dependencies section

dependencies {
    // This dependency is used by the application.
    implementation ''

    // Use JUnit test framework
    testImplementation 'junit:junit:4.13'

    implementation files('libs/org.openni.jar')
  • Modify source file src/main/java/project_setup/ with following code

package project_setup;

import org.openni.OpenNI;
import org.openni.Version;

public class App {
    public static void main(String[] args) {

        Version version = OpenNI.getVersion();

        System.out.println("OpenNI:" + version.getMajor() + "." + version.getMinor());



LD_LIBRARY_PATH=/path/to/openni2/redist/ gradle run


Expect output

OpenNI Version:2.2

Last updated