0

My server is in a Unix environment. And I'm using tomcat server. I'm trying to upgrade the Java version, but tomcat is not starting after the upgrade.

which java still gives the old version.

Below is the script for java pointing to tomcat:

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
Vishrant
  • 15,456
  • 11
  • 71
  • 120
  • `export JAVA_HOME=/my/java/path/` – Michael May 22 '18 at 15:07
  • whee exactly in the script is it defining the java path? @Michael – Sushmitha K May 22 '18 at 15:08
  • What is your tomcat version? What is your current Java version, to which Java version are you trying to upgrade? What errors occur when you start tomcat after upgrading? – Mark Rotteveel May 22 '18 at 15:11
  • @SushmithaK The script doesn't define the `JAVA_HOME` environment variable. It should be in the user's environment. Add it to their `~/.bashrc` or equivalent. – Michael May 22 '18 at 15:11
  • i am upgrading from java 1.7_45 to 1.7_8. and i am suing tomcat7. Tomcat doesnt start after the upgrade. @MarkRotteveel – Sushmitha K May 22 '18 at 15:13
  • i am pretty new to unix. Where can i find the ~/.bashrc or equivalent? @Michael – Sushmitha K May 22 '18 at 15:14
  • 1
    Please update your question with information, don't use comments. In what way is going from 1.7_45 to 1.7_8 an upgrade? That sounds like a downgrade (unless you provided the wrong version nr). And _"doesn't start"_ is not enough information. You should have an error somewhere, either in the tomcat logs, or on the console when starting tomcat. – Mark Rotteveel May 22 '18 at 15:17
  • @SushmithaK `~/.bashrc` is the path of the file. `~` means the user's home directory. `.bashrc` is the name of the file. [The period denotes that it is "hidden"](https://askubuntu.com/questions/94780/what-are-dot-files) – Michael May 22 '18 at 15:19
  • @Michael how can i update the jre path? I am having a really tough time to find where we declard the jre/java path? – Sushmitha K May 22 '18 at 19:31

1 Answers1

0

Tomcat uses JAVA_HOME variable to get the path for Java. So the question drills down to how you set JAVA_HOME and where to set it?

You might find JAVA_HOME under less /etc/profile.d/jdk.sh depending on which shell you are using. I am using cshell so its under /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.

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. 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.

Vishrant
  • 15,456
  • 11
  • 71
  • 120
  • Some of the discussion for this question is done at https://stackoverflow.com/questions/50475870/upgrade-java-jre-path-in-tomcat7 – Vishrant May 23 '18 at 16:31