How to make jni.h?

On Ubuntu 12.04, I have jdk7 installed from sun / oracle. When locate jni.h , it prints multiple locations

 /usr/lib/jvm/java-6-openjdk-amd64/include/jni.h /usr/lib/jvm/jdk1.7.0_07/include/jni.h ... 

The header file generated by the JDK has include <jni.h> and he is currently complaining

 fatal error: jni.h: No such file or directory. 

There is no location specification in my Makefile where jni.h . And I ask if it is possible to configure a specific system parameter to make the jni.h path (say /usr/lib/jvm/jdk1.7.0_07/include/jni.h ) known during compilation.

+33
java classpath jni
Jan 25 '13 at 20:19
source share
6 answers

You must tell your compiler where the include directory is located. Something like that:

 gcc -I/usr/lib/jvm/jdk1.7.0_07/include 

But it depends on your makefile.

+23
Jan 25 '13 at 20:25
source share

He needs jni.h and jni_md.h , try

 gcc -I/usr/lib/jvm/jdk1.7.0_07/include \ -I/usr/lib/jvm/jdk1.7.0_07/include/linux filename.c 

This will include both wide JNI files and those needed for Linux.

+13
Apr 10 '15 at 12:59
source share

Installing the OpenJDK Development Kit (JDK) should fix your problem.

 sudo apt-get install openjdk-X-jdk 

This should make you compile without problems.

+10
Feb 13 '15 at 8:33
source share

Use the following code:

 make -I/usr/lib/jvm/jdk*/include 

where jdk * is the name of your jdk installation directory (e.g. jdk1.7.0).

And there would be no system-wide solution, since the directory name would be different when downloading and installing various JDK collections. If you want an automatic solution, include all the commands in one script and run the specified script in the terminal.

+5
Oct 27 '13 at 12:53 on
source share

Setting JAVA_INCLUDE_DIR where jni.h is located should solve your problem (setting CPPFLAGS does not work for me)

Assuming this is / usr / lib 64 / java / include;

 export JAVA_INCLUDE_DIR=/usr/lib64/java/include 
+1
Aug 24 '17 at 21:27
source share

I usually define my JAVA_HOME variable as follows:

 export JAVA_HOME=/usr/lib/jvm/java/ 

This has the necessary include files. I sometimes add below to my .barshrc when I compile a lot of the things he needs.

0
Jul 03 '15 at 18:37
source share



All Articles