在 /etc/environment 中声明 JAVA_HOME 变量的语法?

在 /etc/environment 中声明 JAVA_HOME 变量的语法?

变量去哪里以及如何JAVA_HOME去?什么,具体来说environment文件内容应该正确放在JAVA_HOME一起吗PATH

当前环境:

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 设置:

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:~$ 

无需编辑用户轮廓

答案1

读完这个问题后:

如何无需重新登录即可从 /etc/environment 重新加载变量?

答案似乎是在source声明之后使用该命令JAVA_HOME第二线:

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:~$ 

然而,它并没有似乎工作,就提出投诉的原因而言JAVA_HOME

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:~$ 

虽然是一个答案,但不确定它是否正确或完整。

相关内容