Re: Is there a JNI Mailing list? [john.boyer@xxxxxxxxxxxxxxxxx: Telling Java where to find a native library]

  • From: "QuentinC" <webmaster@xxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Tue, 24 Aug 2010 14:00:41 +0200

> I may switch to the Sun JDK at some point, but right now i just want to 
get the bindings to load the library, so I can proceed with testing. 
These bindings will be used with other jdk's, inncluding Eclipse.  Prrefer to 
work in a command-line environment.

Eclipse is not a JDK but an IDE. 

I'm sure you will have much less problems if you switch immediately to the 
official sun JDK.
For example on debian and ubuntu , OpenJDK is really a pain. There are many 
topics about various java problems on a french forum I regularely go, and they 
are solved by magic just after they switch without doing anything else.

> The C part of the bindings includes jni.h Will this take care of the 
necesary entry poiints for Java?

If the developper has included jni.h and exported functions whose names start 
with java, yes, it's read for use by java. You have to compile it as a shared 
library.

I had a complete compilation procedure for windows using MinGW, hopes that 
helps. I have infortunately never done JNI outside of windows, so I don't know 
if it works for other systems.
1 - Compile java class
2 - generate C header using javah on the compiled java class
3 - Code C functions using the generated header at step 2
4 - Make a .def file listing all exported functions
5 - Compile C source => gcc -o file.o file.c
6 - Compile shared library => gcc -shared -o file.dll file.def file.c
I think you can try to start at step 4, if somebody gave you the source of a 
java compatible library.

Just a note : I personally don't use JNI anymore. You may look at JNA, which is 
much easier in case you haven't already a wrapper.

Other related posts: