Java/JNI wrapper

Skip to first unread message

Michael Nischt

Nov 29, 2010, 5:52:50 AM11/29/10
to OpenKinect
Hi everyone,

I'd like to contribute the Java/JNI wrapper I wrote recently and hope
it's helpful.

I only tested it on Ubuntu 64bit but in principle it should compile on
any platform. It only comes with a minimal build script which has some
hard-coded paths (for now). Unfortunately, I'm not familiar with
writing cmake scritps and I'm not sure if this would even work with
the Java side.

Anyway, please give it a try and let me know if it works for you:


P.S. Thanks for the great work you all have done!


Nov 29, 2010, 8:24:37 AM11/29/10
to OpenKinect
CMake should support the JNI wrapper. Here is someone using CMake with
a JNI wrapper and the CMakeLists looks simple enough -> I am sure qDot will
appreciate more wrappers, the more accessible kinect is to all
developers the better.




Nov 29, 2010, 10:57:48 AM11/29/10
I'm really interresting in making it Eclipse fragments from it so that it could make OKinect available to Eclipse/Java people.

(Linux/OSX/Win32 on x86 intel would be fantastic).

-- Lucas

Jean-Philippe Encausse

Nov 29, 2010, 11:18:38 AM11/29/10
to OpenKinect
Great Thanks !

I'm really exiting to be able to use Kinect On Win32/Eclipse.
I hope it will be simple to put in eclipse( I had so many headache
with DLL error when combining Java + Kinect + Processing + OpenCV :( )

On Nov 29, 4:57 pm, lucas <> wrote:
> I'm really interresting in making it Eclipse fragments from it so that it
> could make OKinect available to Eclipse/Java people.
> (Linux/OSX/Win32 on x86 intel would be fantastic).
> cheers,

Michael Nischt

Nov 30, 2010, 4:46:08 AM11/30/10
to OpenKinect
Hi all,

As it seems there is great interest in a win(32) version, I will try
to compile ready to use libraries for Java. However, I had spent some
hours compiling libfreenect on windows without success so far. It
would be great if anyone can share how to this, preferred using mingw



Nov 30, 2010, 2:05:36 PM11/30/10
to OpenKinect
I also had a frustrating time with Windows before giving up. Proper
docs and even a downloadable binary would be so nice!


Eidur Arnason

Nov 30, 2010, 2:22:31 PM11/30/10
I second that - any good documentation of  something that works on windows would be much appriciated :)

Best regards. Eiður


Nov 30, 2010, 3:01:38 PM11/30/10
Yeah docs are a little lacking I have tried to install most of the demos where someone has released source on lin win and mac with various degrees of success. The dependancies and versions of code all seem to be interdependant on other apps.

Until you start with a fresh install of OS you don't realise that demo code for project a is dependant on something used for prokect b.

Sent from my BlackBerry

From: Eidur Arnason <>
Date: Tue, 30 Nov 2010 19:22:31 +0000
Subject: Re: Java/JNI wrapper


Nov 30, 2010, 4:22:12 PM11/30/10
to OpenKinect
What took 20 minutes on Ubuntu, (including installing the OS and
prerequisites) wasn't fruitful after many hours on windows 7. I got
one of the precompiled version running, but I think that just caused
more problems with having to uninstall drivers.

Shaun Husain

Nov 30, 2010, 4:30:07 PM11/30/10
I haven't gone down this route yet, I'm mostly interested in using AS3 to do my simple object/blob detection but have been using the as3-server running on a linux box hooked up to the kinect and consuming the TCP stream over my local network on a windows machine (albeit far from speedy) this way I can use Flash Builder (flex) on my Windows box and don't have to mess with trying to get libfreenect or as3-server (consequently libusb) working in Windows.  Have you all been trying the code posted along with the comment in the video below?
or is there a newer method I missed along the way?
Thanks everyone, great work,


Dec 3, 2010, 11:22:03 AM12/3/10
to OpenKinect

Thank you very much for the JNI wrapper. I'm running Fedora 12 (32-
bit) so I thought I'd share what was needed to run your
for that setup. I believe this would be helpful for anyone trying to
run the example who has not worked much with JNI. The only assumption
I make in these instructions is that the user has a proper JDK

1. Install libfreenect based on your repository. See the RedHat/
Fedora instructions here (
Compilation_Guides), but substitute
for (until your code has
been merged into the main repository). Note that you probably don't
have to go beyond the "clone the repository" step, but probably a good
idea to make sure that glview is working before proceeding.
2. Move to the Java wrapper directory: cd ./libfreenect/wrappers/java/
3. Tweak as needed. For me this involved removing the "-m64"
g++ option, changing the line "LIBFREENET_LIBRARY=../../lib/
libfreenect.a" to "LIBFREENET_LIBRARY=../../build/lib/libfreenect.a",
and changing "JDK_HOME" to "JAVA_HOME" (just added "JDK_HOME=$
{JAVA_HOME}" before "JNI_SRC_DIR=OpenKinectJNI"
4. Build the jar: "sh"
5. Compile the demo: "javac -d ./ -classpath .:./dist/OpenKinect.jar ./
6. Move to the executable directory: "cd dist"
7. Change to root: "su"
8. Run the demo: "java -Djava.library.path=. -classpath .:./
OpenKinect.jar Example" Note that the -Djava tells Java where to look
for the native library. Even though is in the
"dist" (current) directory, Java won't see it without the "-D" option
(at least it wouldn't for me - I was getting "Exception in thread
"main" java.lang.UnsatisfiedLinkError: no OpenKinect in

The demo created two jpg files in the current user's directory ("/
root" for me): "kinect.color.jpg" & "kinect.depth.jpg" If you have
those files, you've succeeded.


Dave Pentecost

Dec 3, 2010, 1:40:40 PM12/3/10
I'd suggest that any detailed how-to's (or additions to them, as this appears to be) get posted to the page on the wiki.

Director, Technology
Center for Community

Cell 646 704 2021


Dec 3, 2010, 2:24:16 PM12/3/10
to OpenKinect

Kristiyan Georgiev

Jan 12, 2011, 4:17:19 PM1/12/11
to OpenKinect
Hey I am running NetBeans 6.9 on Ubuntu 10.10 x64

I added the jar to the library/class path, but I get a runtime error

package king.kinect;
public class Main { public static void main( final String[] args ) {
if( NativeKinect.init() ) { int[] buf = NativeKinect.getVideo();
System.out.println( buf.length );
System.out.println( "All good" ); } } }

Exception in thread "main" java.lang.UnsatisfiedLinkError: no kinect
in java.library.path
at java.lang.ClassLoader.loadLibrary(
at java.lang.Runtime.loadLibrary0(
at java.lang.System.loadLibrary(
at king.kinect.NativeKinect.<clinit>(
at king.kinect.Main.main(
Java Result: 1

Any Ideas ?

On Nov 29 2010, 5:52 am, Michael Nischt <>

Jean-Philippe Encausse

Jan 14, 2011, 11:49:13 AM1/14/11
to OpenKinect

Can anybody provides a Win32/Win64 .dll to work with the wrapper under
windows ?
For poor Java Windows developers :)

Reply all
Reply to author
0 new messages