CMake not detecting JNI properly with Temuring jdk 8 in MacOS - java

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

Related

apt install unable to locate executable

I have read a few other threads similar to this one on stack overflow, but I've been unable to solve my problem.
I am trying to install a package.
apt install libgnutls28-dev
however, I get the following error.
Unable to locate an executable at "/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/bin/apt" (-1)
Other people have been able to solve this error by setting the java home environment variable in the terminal.
export JAVA_HOME=/Library/Java/Home
I have tried this, and then run apt install again, but recieved the same error:
Unable to locate an executable at "/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/bin/apt" (-1)
Any help is appreciated!
Hey I encountered this when trying to install libsndfile. Turns out I was reading their instructions for Debian/Ubuntu. apt isn't a thing on macosx. You'll want to use an alternative package installer like brew.
https://unix.stackexchange.com/questions/359219/error-when-using-apt-on-macos-sierra
export JAVA_HOME should point to the directory where the JDK or JRE is installed.
JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::") in a console or directly in .bashrc should do the trick under debian

Installing opencv on openshift for java development

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.

Where is the brew app stored in a Mac?

I'm trying to install a package using Brew, via my Java app (ie no terminal is used).
While my install command works as expected in the terminal, it doesn't work on my Java app. The error is error=2, No such file or directory, so I'm guessing the keyword brew is not recognized.
I'm running my command like this from Java: Runtime.getRuntime().exec("brew install somepackage").
Now I'm trying to find the path to brew so that I could try this: Runtime.getRuntime().exec({"/some/path/to/brew", "install somepackage"}).
My problem is that I don't know where brew is stored in my mac.
Anyone knows?
Thanks
you can run
which brew
on your command line to see the path to your brew binary.
It defaults to /usr/local/bin/brew.
The reason that the call from java does not work is probably caused by the unchanged PATH variable within java, that you changed in your ~/.bash_profile to include /usr/local/bin

cmake can't find java, but it's installed

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

Ant unable to launch, giving a main class error

I'm running Elementary OS (Ubuntu 12 based), and I'm having issues running apache ant. It was working earlier before a restart, so I'm not sure what would've changed.
I've defined environment variables in /etc/environment as follows:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:$ANT_HOME/bin"
JAVA_HOME="/usr/lib/jvm/java-1.7.0-openjdk-i386"
ANT_HOME="/opt/ant"
ANT_OPTS="-Xms256M -Xmx512M"
So my Java and Ant environment variables should be set. I'm trying to deploy with ant, with 'ant clean deploy', but I get an error in my terminal:
Error: Could not find or load main class org.apache.tools.ant.launch.Launcher
I've tried "source /etc/environment". Running 'echo $ANT_HOME' shows the correct path. I've tried moving ant to a different location and resetting the variables. Nothing. I'm kind of lost. Please help!
you should define $ANT_HOME before using it in your $PATH
JAVA_HOME="/usr/lib/jvm/java-1.7.0-openjdk-i386"
ANT_HOME="/opt/ant"
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:$ANT_HOME/bin"
double check that you have ant-launcher.jar under $ANT_HOME/lib
As others have stated, it looks like ANT_HOME isn't being set before you declare it in your path.
I take a slightly different approach to these things. Instead of constantly updating my PATH, I usually set my path to something fairly simple:
PATH="/usr/local/bin:/bin:/usr/bin/:$HOME/bin"
Then, I make hard links to various binaries into my /usr/local/bin directory.
$ cd $ANT_HOME/bin # All the Ant binaries
> for binary in *
> do
> sudo ln -s $PWD/$binary /usr/local/bin
> done
Now, I don't have to add $ANT_HOME/bin to my $PATH. Even better, if I include /usr/local/bin before /usr/bin and /bin, I am picking the binary in /usr/local/bin first. This way, I can ensure I run the version I installed over the default. For example, my machine comes with Ant 1.7 in /usr/bin/ant but I want to use Ant 1.9.1. I can install Ant 1.9.1, and that will be my default version.
I had same error when install ant with npm install. When I tried install from official repository throw pacman -S apache-ant(apt-get install apache-ant -- for Debian/Ubuntu) it's start working proper for me.
I'm experiencing this bug with jdk 1.8. But, I came across this RHEL 6.5 bug for OpenJDK 1.8 which may be related:
https://bugzilla.redhat.com/show_bug.cgi?id=1149605
Essentially, it's fixed in jpackage-utils-1.7.5-3.13 which is included with RHEL 5.7.
The problem, as Javier Ramirez said in the bug comments:
Your script /usr/share/java-utils/java-functions has problems with
"openjdk version" because it expects "java version" as Java 7 does.
$ mkdir /usr/share/java-1.8.0
$ mkdir /usr/lib/java-1.8.0
$ diff /usr/share/java-utils/java-functions.orig /usr/share/java-utils/java-functions
149,150c149,150
< -e '/java \(full \)*version "/s/'$re'/<<<\1>>>/' \
< -e '/java \(full \)*version "/s/.*<<<\([^>]\{1,\}\)>>>.*/\1/p')
---
> -e '/[java|openjdk] \(full \)*version "/s/'$re'/<<<\1>>>/' \
> -e '/[java|openjdk] \(full \)*version "/s/.*<<<\([^>]\{1,\}\)>>>.*/\1/p')
------
I am using RHEL which comes with ant (in /usr/bin/ant) and the ant libraries in
/usr/share/ant. As suggest above, ant -version gave the "could not find" error.
I installed my own version of ant (in /home/Ant since I have a lot of space
in /home) and put ANT_HOME in my .bash_profile and $ANT_HOME/bin in my PATH
and $ANT_HOME and $ANT_HOME/bin (for good measure) in my CLASSPATH. Then ant
worked (when used as myself, not as root).

Categories

Resources