I am trying to build a project with cmake. This project is using java among other things.
The problem is that at the code
find_package(Java REQUIRED)
I receive the following error:
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:108
(message):
Could NOT find Java (missing: Java_JAVA_EXECUTABLE Java_JAR_EXECUTABLE
Java_JAVAC_EXECUTABLE Java_JAVAH_EXECUTABLE Java_JAVADOC_EXECUTABLE)
Call Stack (most recent call first):
/usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:315 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-2.8/Modules/FindJava.cmake:195 (find_package_handle_standard_args)
CMakeLists.txt:66 (find_package)
Though
which java
outputs
/usr/bin/java
How come? What can be the reason of this error?
If you are using the linux os then you have to set the java home like export
JAVA_HOME=/home/aqeel/development/jdk/jdk1.6.0_35
export PATH=$JAVA_HOME/bin:$PATH
Related
I am building a library on Mac Big Sur using Java 8 from Adoptium (Eclipse Temurin).
To install Java, I am using the following commands:
brew tap homebrew/cask-versions
brew install --cask temurin8
Then, I export JAVA_HOME like this:
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
And it properly exports it. When I execute echo $JAVA_HOME, it returns:
/Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home
However, while building the library, it tries to find JNI, and it is returning the following lines:
CMake Error at /usr/local/Cellar/cmake/3.24.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find JNI (missing: JAVA_INCLUDED_PATH JAVA_INCLUDED_PATH2 AWT)
Is there anything else necessary to make this work on MacOS?
Notes:
I installed cmake using brew (brew install cmake).
I have already searched in Google and StackOverflow, and none of the proposed solutions worked (I have also checked the recommended similar questions while creating this one).
I checked the variable values in the FindJNI.cmake file and everything seems correct (it should find it).
In FindJNI.cmake, the value of JAVA_AWT_INCLUDE_DIRECTORIES is correct (/Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home/include), and jni.h is inside that directory. However, find_path(JAVA_INCLUDE_PATH 'jni.h' $(JAVA_AWT_INCLUDE_DIRECTORIES)) is not setting JAVA_INCLUDE_PATH properly.
I created a dummy project using find_path(TEST 'jni.h' '/Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home/include'), looking for jni.h and it works. TEST contains the correct value.
Thank you.
Edit:
This is the call to find_package:
find_package(JNI 1.7 REQUIRED)
I was finally able to solve this by setting the requested variables as flags for cmake. I just appended the following to my cmake call:
cmake ... -DJAVA_HOME=$(/usr/libexec/java_home -v 1.8) -DJAVA_INCLUDE_PATH=$(/usr/libexec/java_home -v 1.8)/include -DJAVA_INCLUDE_PATH2=$(/usr/libexec/java_home -v 1.8)/include/darwin -DJAVA_AWT_INCLUDE_PATH=$(/usr/libexec/java_home -v 1.8)/include
I continue to have trouble installing and loading rJava. I have R 3.4.1 ('Single Candle'); Java v 9 and mac OS 10.12.6.
I followed all of the steps listed here which included using Terminal to edit my ~/.profile to include:
export JAVA_HOME=$(/usr/libexec/java_home -v 9)
export PATH=$JAVA_HOME/bin:$PATH
And making other changes to connect R to the 'right' Java. When I run
sudo R CMD javareconf
however, I get an error message that says:
warning: ‘JNI_CreateJavaVM’ is deprecated
[-Wdeprecated-declarations]
JNI_CreateJavaVM(0, 0, 0);
^
/System/Library/Frameworks/JavaVM.framework/Headers/jni.h:1937:1: note:
‘JNI_CreateJavaVM’ has been explicitly marked deprecated here
JNI_CreateJavaVM(JavaVM **pvm, void **penv, void *args);
^
1 warning generated.
And when I run
R CMD INSTALL rJava_0.9-8.tar.gz
Everything goes smoothly until I get an error that says:
checking whether JNI programs can be compiled… configure: error: Cannot compile a simple JNI program. See config.log for details.
Make sure you have Java Development Kit installed and correctly registered in R.
If in doubt, re-run “R CMD javareconf” as root.
ERROR: configuration failed for package ‘rJava’
Michal from the site linked above kindly suggested to make sure that '/usr/libexec/java_home -v 9' "points" to JDK and not JRE. I am not sure how to do this. Also when I try something like:
echo $JAVA_HOME
I get:
/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home
How do I know if this JDK or JRE?
Due to my error messages, I think I have a JNI problem, but I am not sure how to go about STARTING to deal with that issue. Any insight regarding what might have gone wrong using Michal's tutorial would be greatly appreciated!
P.S. My original issue was in R, trying to load library(rJava) and getting this error:
Error: package or namespace load failed for ‘rJava’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: #rpath/libjvm.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so
Reason: image not found
I followed this link, especially:
Administrator account user
Issue the following commands at the terminal:
export JAVA_HOME=${JAVA_HOME:-$(/usr/libexec/java_home)}
export LIBJVM=$(find "${JAVA_HOME}" -name 'libjvm.dylib')
R CMD javareconf JAVA_LIBS="${LIBJVM}" JAVA_LD_LIBRARY_PATH="${LIBJVM}" JAVA_CPPFLAGS="'-I${JAVA_HOME}/include -I${JAVA_HOME}/include/darwin -I$(dirname "${LIBJVM}")'"
ln -fs "$LIBJVM" /Library/Frameworks/R.framework/Libraries
The installation worked!
You can do following to test whether your Java 9 is JDK. Do following:
> git clone https://github.com/mkowsiak/jnicookbook.git
> cd jnicookbook/recipes/recipeNo001
> export JAVA_HOME=$(/usr/libexec/java_home -v 9)
> export PATH=$JAVA_HOME/bin:$PATH
> make
> make test
If you see
Hello world!
at the end, it means your JDK can compile JNI code. Now, if it works, it means rJava is still using incorrect Java installation (e.g. one from Apple). In that case, you need to take a look inside error log of rJava to make sure what is used there.
I hope this will help you at least a little bit.
I'm trying to build AOSP from source (With a few modifications) but my build stops with
[ 0% 1/35196] JarJar: out/target/common/obj/JAVA_LIBRARIES/conscrypt_intermediates/classes-jarjar.jar
FAILED: /bin/bash -c "java -jar out/host/linux-x86/framework/jarjar.jar process external/conscrypt/jarjar-rules.txt out/target/common/obj/JAVA_LIBRARIES/conscrypt_intermediates/classes-full-debug.jar out/target/common/obj/JAVA_LIBRARIES/conscrypt_intermediates/classes-jarjar.jar"
Error: Could not find or load main class com.tonicsystems.jarjar.Main
ninja: build stopped: subcommand failed.
make: *** [build/core/ninja.mk:149: ninja_wrapper] Error 1
and i can't get to fix it. My source is hosted here and the path of external/jarjar is the stock one on googlesource.
Can anyone help?
I had the same problem until I realized that it's due to the wrong path where com.tonicsystems.jarjar.Main is located. At ~/android/system, JarJar's com.tonicsystems.jarjar class is located in:
external/jarjar/src/main/com/tonicsystems
When it should be
external/jarjar/src/main/java/com/tonicsystems
Like it's source (from GitHub)
src/main/java/com/tonicsystems/jarjar
P.S: I had to create the external/jarjar/src/main/java directory and then move the source.
I've run into this with an AOSP fork (I think Qualcomm's tree) before - that was caused by the Makefile fragments that generate the file lists for the jar files not dealing properly with localized versions of the "sort" utility (causing removal of important class files in addition to the duplicates that were supposed to be removed).
I don't remember all the details or the proper fix, but the workaround that got me going initially was simply disabling localization while building.
rm -rf out
export LANG=C
export LC_ALL=C
export LC_COLLATE=C
. build/envsetup.sh
lunch whatever
make droidcore -j8
What fixed this for me was something completely unrelated to jarjar itself.
I was building AOSP 7.1.1 on Ubuntu 20.04. The default python command on Ubuntu 20.04 points to python3 [1], but AOSP 7.1.1 builds using python (which is really python 2.7.5).
I updated my system with sudo apt install python which linked the python command to python2 correctly instead of python3. After this, I built successfully.
AOSP is shipped with python under the prebuilts/python directory and I'm still confused as to why the build system doesn't point to that python version.
Edit
I had more trouble with adjusting my system to use the correct version of python, ultimately I had to add python and python3 as alternatives.
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2
$ sudo update-alternatives --config python
Select python2
I am trying to install opencv on openshift. following the post mentioned here
http://codingexodus.blogspot.in/2013/04/how-to-install-opencv-on-openshift.html
I am developing in java so i have installed jdk1.8 and apache ant into the $OPENSHIFT_DATA_DIR
I had to install apache ant also so i did the same again in the $OPENSHIFT_DATA_DIR
my JAVA_HOME is set to the jdk and even ANT_HOME is also pointing to the right place
JAVA_HOME="$OPENSHIFT_DATA_DIR/jdk1.8.0_05"
I am doing a cmake in the end to generate the makefile with the command
cmake -D CMAKE_BUILD_TYPE=RELEASE -D BUILD_SHARED_LIBS=OFF ..
going through the cmake output i do see that for java it has found the ant, jni etc. finally when i execute a
make
make install
i get the error
make: *** No targets specified and no makefile found. Stop.
there is no make file generated. what am missing.
I am trying to install JNetPcap and followed the instructions given at here. At step 12, I am unable to run the ant command and i see the error
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/lib/jvm/java-6-sun/bin/java
As I am able to run Java classes from eclipse or from command line I don't think if it's a problem with JAVA_HOME.
echo $PATH shows
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/jvm/java-6-sun/bin
Kindly let me know if am missing something here.
thanks in advance
Neither running java from the command line or running eclipse will require JAVA_HOME to be set. However, the build procedure you are trying to use ant, and ant often does require JAVA_HOME to be set appropriately. (It actually depends on the version of ant that you are using. The use of JAVA_HOME is typically in the wrapper script for ant.)
Just set it.
JAVA_HOME should probably be set to /usr/lib/jvm/java-6-sun ... based on what you gave said PATH to.
However, it is also possible that the problem is that your PATH is incorrect. Or that you have (somehow) managed to get the owner/group/permissions on your Java install incorrect, such that the java command isn't executable.
Check that running java -version displays the installed Java version.
Repeat with /usr/lib/jvm/java-6-sun/bin/java -version.