Ubuntu

Ubuntu 導出 JAVA_HOME ,ANT_HOME

  • June 24, 2011
Ubuntu 11.04
open terminal
JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.24/
export JAVA_HOME
echo $JAVA_HOME 
==>/usr/lib/jvm/java-6-sun-1.6.0.24/

i close the terminal 
open another terminal
echo $JAVA_HOME 
==>

知道為什麼沒有保存 JAVA_HOME 嗎?

您缺少“永久”的“-p”。

它有一些錯誤,但這是我使用的。

# Set the JAVA_HOME variable
function set_java_home {
 echo "Searching for java ..."
 if [ -z $JAVA_HOME ]; then
     echo "Using default value for JAVA_HOME: /usr/java/default"
     JAVA_HOME=/usr/java/default
 fi
 export -p JAVA_HOME
 echo $JAVA_HOME > java.home.config
 sudo rm /etc/alternatives/java
 sudo ln -s $JAVA_HOME/bin/java /etc/alternatives/java
 echo "JAVA_HOME variable set to $JAVA_HOME and /etc/alternatives set."
}
if [ -f java.home.config ]; then
 JAVA_HOME=$(<java.home.config)
else
 JAVA_HOME_CANDIDATES=$(find /usr -type d -name '*jdk1.6*')
 echo "Found the following candidates for JAVA_HOME. Pick one: "
 echo "---"
 echo $JAVA_HOME_CANDIDATES
 echo "---"
 read USER_SUBMITTED_JAVA_HOME
 echo "You chose $USER_SUBMITTED_JAVA_HOME ."
 JAVA_HOME=${USER_SUBMITTED_JAVA_HOME}
fi
set_java_home

引用自:https://serverfault.com/questions/283953