简体   繁体   English

如何在tomcat服务器中升级Java?

[英]How to upgrade Java in tomcat server?

My server is in a Unix environment. 我的服务器在Unix环境中。 And I'm using tomcat server. 我正在使用tomcat服务器。 I'm trying to upgrade the Java version, but tomcat is not starting after the upgrade. 我正在尝试升级Java版本,但是在升级后tomcat无法启动。

which java still gives the old version. which java仍然提供旧版本。

Below is the script for java pointing to tomcat: 下面是指向tomcat的java脚本:

if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then
    some script
fi
else
    JAVA_PATH=`which java 2>/dev/null`
    if [ "x$JAVA_PATH" != "x" ]; then
      JAVA_PATH=`dirname $JAVA_PATH 2>/dev/null`
      JRE_HOME=`dirname $JAVA_PATH 2>/dev/null`
    fi
    if [ "x$JRE_HOME" = "x" ]; then
      if [ -x /usr/bin/java ]; then
        JRE_HOME=/usr
      fi
    fi
  fi
  if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then
    echo "Neither the JAVA_HOME nor the JRE_HOME environment variable is defined"
    echo "At least one of these environment variable is needed to run this program"
    exit 1
  fi
fi

Tomcat uses JAVA_HOME variable to get the path for Java . Tomcat使用JAVA_HOME变量来获取Java的路径。 So the question drills down to how you set JAVA_HOME and where to set it ? 因此,该问题深入到如何设置JAVA_HOME以及在哪里设置

You might find JAVA_HOME under less /etc/profile.d/jdk.sh depending on which shell you are using . 您可能会在less /etc/profile.d/jdk.sh下找到JAVA_HOME这取决于您使用的是哪个shell I am using cshell so its under /etc/profile.d/jdk.csh 我正在使用cshell因此它在/etc/profile.d/jdk.csh

If you will check less /etc/profile , this is the file which is loaded when a user logs in. There is a variable called as PATH the value for which might be something like /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin so you can access any executable under these paths. 如果您less /etc/profile检查less /etc/profile ,那么这是用户登录时加载的文件。有一个名为PATH的变量,其值可能类似于/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin因此您可以在这些路径下访问任何可执行文件。

The line in ponder in /etc/profile is for i in /etc/profile.d/*.sh from where all the variable (in case of bash ) will be loaded into the environment. /etc/profile中考虑的行是for i in /etc/profile.d/*.sh ,所有变量(如果为bash )将从此处加载到环境中。 Also, it's important to note, if you are setting values here these variable will be set for all the users not just for one. 另外,请务必注意,如果您在此处设置值,那么将为所有用户设置这些变量,而不仅仅是为一个用户。

You might find this and this answer useful. 您可能会发现这个回答很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM