The Leap Motion Java SDK uses a standard Jar file for Leap Motion API class definitions and a set of native libraries that allow your Leap-enabled Java programs to exchange data with the Leap. Setting up a Java project typically involves adding the LeapJava.jar file to your application’s classpath and setting the JVM library path parameter so that your JVM can find the native libraries.
The Leap Motion Jar file is cross-platform, but the native libraries must match the platform and architecture of the JVM used to run the program.
To use the Leap Motion SDK in a Java program, you must add the LeapJava.jar file to the classpath and set the java.library.path to the location of the Leap Motion native libraries.
Use the following Java and native libraries with the Leap Motion Java SDK:
Use the Java compiler, javac to compile, setting the classpath option to specify the LeapJar file. For example, to compile the Sample.java program included in the Leap Motion SDK, you could use the following command:
javac -classpath <LeapSDK>/lib/LeapJava.jar Sample.java
(where <LeapSDK> is the location of your Leap Motion SDK folder.)
To launch a Leap-enabled program, Java needs to find the Leap Motion native libraries at runtime. LeapJava.jar must also be on the classpath. You can set Java’s java.library.path parameter to identify the native library. The command line syntax is slightly different between Mac and Windows. More importantly, on Windows, you have to specify either the 32-bit or the 64-bit libraries to match the architecture of the JVM you are using.
On Mac, you could run the Sample program using the following command:
java -classpath ".:<LeapSDK>/lib/LeapJava.jar" -Djava.library.path=<LeapSDK>/lib Sample
On Windows, you could run the Sample program using a 64-bit JVM with the following command:
java -classpath ".;<LeapSDK>/lib/LeapJava.jar" -Djava.library.path=<LeapSDK>/lib/x64 Sample
In the Eclipse IDE, you add the LeapJava.jar file to a project as an external Jar and then set the path to the appropriate native Leap Motion libraries as a property of the Jar file.
On Windows, be sure to select the folder containing the correct libraries for your target architecture. If you are targeting a 32-bit JVM, use the Leap Motion libraries in the x86 folder of the SDK. If you are targeting a 64-bit JVM, use the libraries in the x64 folder. On Mac, each Leap Motion library file supports both architectures.
Note: you can also add the Leap Motion libraries to an existing project from the Project Properties dialog.
In the IntelliJ IDE, you add the LeapJava.jar file to a project as a library. You separately set the path to the Leap Motion native libraries using the JVM parameter, java.library.path. The JVM parameters can be set using an IntelliJ Run/Debug configuration.
To add LeapJava.jar to the project:
To set the path to the native Leap Motion libraries by creating a Run/Debug configuration:
In the NetBeans IDE, you add the LeapJava.jar file to a project as a library. You separately set the path to the Leap Motion native libraries using the JVM parameter, java.library.path. The JVM parameters can be set using a NetBeans Run configuration.
To add the LeapJava.jar to a project and set the path to the native libraries: