我正在尝试将我的服务器从 Java7 升级到 Java8,以便它们可以在 Java8 下运行我的 Web 应用。在我的其中一台机器上,我收到以下错误,我不确定什么仍然指的是 java-7
$ sudo service tomcat7 start
* Starting Tomcat servlet engine tomcat7
start-stop-daemon: unable to stat /usr/lib/jvm/java-7-oracle/bin/java (No such file or directory)
此服务器是 Ubuntu 14.10 (Utopic)。我已卸载所有 java-7 和 java-6 包。我现在安装了以下 java 包:
- openjdk-8-jdk
- openjdk-8-jre
- openjdk-8-源
- oracle-java8-安装程序
我有一个/usr/share/tomcat7/bin/setenv.sh文件中含有以下行:
JAVA_HOME=`readlink -f /usr/bin/javac | sed 's|/bin/javac||g'`
Java 替代品似乎指向正确的事情:
$ update-alternatives --display java
java - manual mode
link currently points to /usr/lib/jvm/java-8-oracle/jre/bin/java
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java - priority 1069
slave java.1.gz: /usr/lib/jvm/java-8-openjdk-amd64/jre/man/man1/java.1.gz
/usr/lib/jvm/java-8-oracle/jre/bin/java - priority 1080
slave java.1.gz: /usr/lib/jvm/java-8-oracle/man/man1/java.1.gz
Current 'best' version is '/usr/lib/jvm/java-8-oracle/jre/bin/java'.
Java 8 可以正常工作:
$ java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
我不明白为什么某些东西仍在寻找 java-7。以下 grep 没有显示任何线索:
$ sudo grep -r java-7 /etc/tomcat7 /etc/init.d/tomcat7 /var/lib/tomcat7/ /usr/share/tomcat7
是什么原因导致 tomcat7 仍然寻找 java-7?
答案1
参考文献是/etc/default/tomcat7
:
JAVA_HOME=/usr/lib/jvm/java-7-oracle
我将其更新为 java-8,一切正常。以下是我进行升级的完整脚本:
#!/bin/sh
set -e
sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get update
sudo apt-get --force-yes -y install \
openjdk-8-jdk \
openjdk-8-jre \
openjdk-8-source \
oracle-java8-installer
sudo apt-get --force-yes -y remove \
openjdk-6-jdk \
openjdk-6-jre \
openjdk-6-jre-headless \
openjdk-6-source \
openjdk-7-jdk \
openjdk-7-jre \
openjdk-7-jre-headless \
openjdk-7-source \
oracle-java6-installer \
oracle-java7-installer
echo "Setting java provider to java-8-oracle"
sudo update-java-alternatives --set java-8-oracle || true
currentjava=`update-alternatives --display java | grep 'points to'`
if [ "$currentjava" == "${currentjava/java-8-oracle/}" ]
then
echo "Java not set properly"
exit 1
fi
sudo sed -i -r "s#^JAVA_HOME=.*#JAVA_HOME=\`readlink -f /usr/bin/javac | sed 's|/bin/javac||g'\`#" /etc/default/tomcat7
sudo service tomcat7 stop
sleep 4
sudo killall -u tomcat7 || true
sleep 3
sudo service tomcat7 start