What is the right way for JAVA_HOME on a Linux system using alternatives?

Finding the right path for JAVA_HOME bit complicated on Ubuntu , as it uses alternatives. On my machine, this is how alternatives create at least two levels of indirection before they get into actual java or javac.

 usr/bin/javac -> /etc/alternatives/ /etc/alternatives/java -> /usr/lib/jvm/jdk1.7/bin/javac 

If I set JAVA_HOME to /usr/lib/jvm/jdk1.7 , it is possible that my system java may become incompatible with the java that JAVA_HOME points to if I update alternatives to use another java.

My question is: what is the correct value for JAVA_HOME on a system using alternatives. I tend to think JAVA_HOME should be installed on /usr

This TOMCAT method or any other software that uses it will add β€œbin” to JAVA_HOME and find all the executables it needs.

This is the correct value for JAVA_HOME for alternate systems. Do you use most JAVA_HOME software only to search for executable files, or will they use the value to search for other artifacts (such as a security policy file, etc.) that come with the JDK? If the former is true, then I feel that we can use /usr for JAVA_HOME , but if the latter is true, then I believe that the only way to use JAVA_HOME correctly is to sacrifice alternative functionality.

+7
source share
1 answer

Good question - I use "alternatives" for Linux, and everything "just works" - I never had to think about it.

I believe this is the answer:

1) "alternatives" establishes a symbolic link to the fact that your "real" Java is currently set to

2) All you have to do is set $ JAVA_HOME to a symbolic link

+5
source

All Articles