0

Where and how does the variable JAVA_HOME go? What, specifically, should the environment file contents be to correctly set JAVA_HOME alongside PATH?

current environment:

thufir@doge:~$ 
thufir@doge:~$ cat /etc/environment 
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
thufir@doge:~$ 

Java settings:

thufir@doge:~$ 
thufir@doge:~$ java -version
openjdk version "1.8.0_121"
OpenJDK Runtime Environment (build 1.8.0_121-8u121-b13-0ubuntu1.16.10.2-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)
thufir@doge:~$ 
thufir@doge:~$ which java
/usr/bin/java
thufir@doge:~$ 
thufir@doge:~$ sudo update-alternatives --config java
[sudo] password for thufir: 
There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
Nothing to configure.
thufir@doge:~$ 
thufir@doge:~$ echo JAVA_HOME
JAVA_HOME
thufir@doge:~$ 

without editing the user profile.

Thufir
  • 4,551

1 Answers1

0

After reading this question:

How to reload variables from /etc/environment without re-logging in?

the answer would appear to be to use the source command, after declaring JAVA_HOME on a second line:

thufir@doge:~$ 
thufir@doge:~$ source /etc/environment
thufir@doge:~$ 
thufir@doge:~$ cat /etc/environment 
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
JAVA_HOME="/usr/bin/java"
thufir@doge:~$ 
thufir@doge:~$ which java
/usr/bin/java
thufir@doge:~$ 
thufir@doge:~$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
thufir@doge:~$ 
thufir@doge:~$ echo $JAVA_HOME
/usr/bin/java
thufir@doge:~$ 
thufir@doge:~$ sudo update-alternatives --config java
There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
Nothing to configure.
thufir@doge:~$ 

However, it doesn't seem to work, insofar as the reason for setting JAVA_HOME complains:

thufir@doge:~$ 
thufir@doge:~$ jars/apache-cxf-3.1.11/bin/wsdlvalidator
ERROR: Set JAVA_HOME to the path where the J2SE 6.0 (JDK6.0) is installed
thufir@doge:~$ 

While an answer, not sure that it's correct or complete.

Thufir
  • 4,551