Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect Java location from Makefile

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

like image 525
Chrisc Avatar asked Dec 09 '22 14:12

Chrisc


2 Answers

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

like image 104
mab Avatar answered Dec 12 '22 03:12

mab


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());')
like image 29
Ahmad AlMughrabi Avatar answered Dec 12 '22 05:12

Ahmad AlMughrabi