Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
871 views
in Technique[技术] by (71.8m points)

cmake find_package(JNI) not work in Ubuntu 12.04 amd64

I am using cmake 2.8.7 on Ubuntu 12.04 amd64. The installed OpenJDK JRE components in my system are listed below :

$ sudo dpkg --list | grep jdk
openjdk-6-jre   6b27-1.12.5-0ubuntu0.12.04.1   OpenJDK Java runtime, using Hotspot JIT
openjdk-6-jre-headless   6b27-1.12.5-0ubuntu0.12.04.1   OpenJDK Java runtime, using Hotspot JIT (headless)
openjdk-6-jre-lib   6b27-1.12.5-0ubuntu0.12.04.1   OpenJDK Java runtime (architecture independent libraries)

However, I am not using the OpenJDK JRE components. I have manually installed Oracle Java 7 JDK in "/usr/lib/jvm/jdk1.7.0_25" and have used "update-alternatives" to point "java" to my installed Oracle Java 7 JDK. I have not set any "JAVA_HOME", "JAVA_BIN", "CLASSPATH" environment variables and the manually installed Oracle Java 7 JDK seems work OK in Eclipse 4.3.

The problem is that when I use "find_package(JNI)" in cmake and use the "message()" function to show the JNI variables, I have the following result :

Could NOT find JNI (missing:  JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH) 
JNI_FOUND = FALSE
JNI_LIBRARIES = /usr/lib/jvm/java-6-openjdk/jre/lib/amd64/libjawt.so;/usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server/libjvm.so
JAVA_INCLUDE_PATH = JAVA_INCLUDE_PATH-NOTFOUND
JAVA_INCLUDE_PATH2 = JAVA_INCLUDE_PATH2-NOTFOUND
JAVA_AWT_INCLUDE_PATH = JAVA_AWT_INCLUDE_PATH-NOTFOUND
JAVA_JVM_LIBRARY = /usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server/libjvm.so
JAVA_AWT_LIBRARY = /usr/lib/jvm/java-6-openjdk/jre/lib/amd64/libjawt.so
JNI_INCLUDE_DIRS = JAVA_INCLUDE_PATH-NOTFOUND;JAVA_INCLUDE_PATH2-NOTFOUND;JAVA_AWT_INCLUDE_PATH-NOTFOUND

The "find_package(JNI)" seems could find some of the Java components related to the OpenJDK JRE and could not find my current Oracle Java 7 JDK components pointed by "update-alternatives".

I want to know that is there any bug in the "FindJNI.cmake" file and what I have missed in the Oracle Java 7 JDK setup so that cmake "find_package(JNI)" could work properly.

Thanks for any suggestion.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can manually modify FindJNI.cmake to help it find your installed JDK. See this gist:

https://gist.github.com/emchristiansen/6845954

It's a shame this script hasn't been updated, but maybe not a surprise, given that CMake is such a disaster.

EDIT: A more straightforward solution is to set JAVA_HOME properly. With OpenJDK 7 installed, I set it with:

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...