Setting up a project

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.

Leap Motion Java 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:

  • 32-bit Windows:
    • LeapSDK/lib/LeapJava.jar — Leap Motion Java API class definitions
    • LeapSDK/lib/x86/LeapJava.dll — 32-bit Leap Motion Java library for Windows
    • LeapSDK/lib/x86/Leap.dll — 32-bit Leap Motion library for Windows
  • 64-bit Windows:
    • LeapSDK/lib/LeapJava.jar — Leap Motion Java API class definitions
    • LeapSDK/lib/x64/LeapJava.dll — 64-bit Leap Motion Java library for Windows
    • LeapSDK/lib/x64/Leap.dll — 64-bit Leap Motion library for Windows
  • 32- or 64-bit Mac OS:
    • LeapSDK/lib/LeapJava.jar — Leap Motion Java API class definitions
    • LeapSDK/lib/libLeapJava.dylib — Leap Motion Java library for Mac
    • LeapSDK/lib/libLeap.dylib — Leap Motion library for Mac

Compile from the command line

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.)

Run from the command line

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

Eclipse

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.

  1. Select New > Java Project from the Eclipse File menu.
  2. Assign a name to the project on the Create Java Project page and set other properties as desired. (The Leap Motion SDK supports Java 6 and 7.)
  3. Click Next to advance to the Java Settings page.
  4. Select the Libraries tab.
  5. Click the Add External Jars... button.
  6. Navigate to the LeapJava.jar file.
  7. Click Open to add LeapJava.jar to the project.
  8. Next, click the small triangle in front of the LeapJava.jar entry in the library list to reveal the library properties.
https://di4564baj7skl.cloudfront.net/documentation/images/Setup_Eclipse_Jar_Properties.png
  1. Select the Native library location item.
  2. Click the Edit button.
  3. Navigate to the folder containing the Leap Motion native libraries.
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.
  1. Click Ok to set the path.

Note: you can also add the Leap Motion libraries to an existing project from the Project Properties dialog.

IntelliJ

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:

  1. After creating a project in the usual way, select the File > Project Structure menu command to open the settings dialog.
  2. Click Libraries under project settings.
  3. Click the small + button at the top of the library list to open the Select Library Files dialog.
  4. Add LeapJava.jar from your Leap Motion SDK.

To set the path to the native Leap Motion libraries by creating a Run/Debug configuration:

  1. Select the Run > Edit Configurations… menu command.
  2. Click the small + button above the Configuration list.
  3. Choose Application to create a new application configuration.
  4. Assign a name.
  5. Set the VM Options field to set the -Djava.library.path parameter to the path to the proper folder containing the Leap Motion native libraries.
  6. Click Ok.
https://di4564baj7skl.cloudfront.net/documentation/images/Setup_IntelliJ_Properties.png

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.

NetBeans

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:

  1. After creating a project in the usual way, select the File > Project Properties menu command to open the Project Properties dialog.
  2. Click the Libraries item.
  3. Click Add Jar/Folder button.
  4. Find the LeapJava.jar file in your Leap Motion SDK.
  5. Click Ok to add the Jar file to your project.
  6. Next, click the Run item in the Project properties list
  7. Set the VM Options field to set the -Djava.library.path parameter to the path to the proper folder containing the Leap Motion native libraries.
https://di4564baj7skl.cloudfront.net/documentation/images/Setup_Netbeans_Properties.png

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.