Linux
嘗試使用 Java8 執行 Tomcat7 時“無法統計 /usr/lib/jvm/java-7-oracle/bin/java”
我正在嘗試將我的伺服器從 Java7 升級到 Java8,以便它們將在 Java8 下執行我的 webapps。在我的一台機器上,我收到以下錯誤,我不確定什麼仍然指的是 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-installer
我有一個*/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?
參考在
/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