I have a makefile, which needs to know the location of the Java include directory because it makes use of the jni.h file. What is the best way of allowing the Makefile to auto-detect where Java is installed on Linux?
Thanks,
Chris
I have a makefile, which needs to know the location of the Java include directory because it makes use of the jni.h file. What is the best way of allowing the Makefile to auto-detect where Java is installed on Linux?
Thanks,
Chris
How about using
JAVA_HOME=$(shell readlink -f /usr/bin/javac | sed "s:bin/javac::")
Adapted from: https://serverfault.com/questions/143786/how-to-determine-java-home-on-debian-ubuntu
You can try this too:
JAVA_HOME:=$(jrunscript -e 'java.lang.System.out.println(new java.io.File(java.lang.System.getProperty("java.home")).getParent());')
The JAVA_HOME environment variable contains the path to the Java installation.
On Linux you can use the which
command, such as which java
. It should tell you where the location of the java exec it would use is.
However, I'd recommend setting up JAVA_HOME as Erick pointed out.
/etc/alternatives/java
, which is not very helpful
ant
than with make
.