How to set JAVACMD

5,603

Replace JAVA_HOME in the /etc/tomcat/tomcat.conf with /usr/java/jre1.8.0_51

Share:
5,603

Related videos on Youtube

Roy Hinkley
Author by

Roy Hinkley

Updated on September 18, 2022

Comments

  • Roy Hinkley
    Roy Hinkley almost 2 years

    I have a Tomcat7 install on a CentOS (6.7) system. Tomcat will not run, throwing exception in catalina.out

    /usr/sbin/tomcat: line 29: -classpath: command not found
    

    and related tomcat-initd.log

    /usr/sbin/tomcat: error: Failed to set JAVACMD
    

    According to this SF post, I should be able to set it in /usr/share/java-utils/java-functions like this:

    # Add all sorts of jvm layouts here
      if [ -x "$JAVA_HOME/jre/sh/java" ]; then
        JAVACMD="$JAVA_HOME/jre/sh/java"
      elif [ -x "$JAVA_HOME/bin/java" ]; then
        JAVACMD="$JAVA_HOME/bin/java"
      else
        JAVACMD=`which java 2>/dev/null`
      fi
    
      if [ ! -x "$JAVACMD" ]; then
        echo "$0: error: Failed to set JAVACMD"
        return 1
      fi
    

    But I still get the exception. What's missing? What am I not understanding, and how do I resolve the exception?

    JAVA_HOME is set:

    echo $JAVA_HOME
    /usr/java/jdk1.7.0_79
    

    Checking tomcat status:

    sudo service tomcat status
    PID file exists, but process is not running                [WARNING]
    tomcat lockfile exists but process is not running          [FAILED]
    

    This is true even after deleting the Tomcat pid file, rinsing and repeating.

    Request responses:

    whereis java
    java: /usr/bin/java /etc/java /usr/lib/java /usr/share/java
    
    ls -lad /usr/bin/java
    lrwxrwxrwx. 1 root root 21 Jul 21  2015 /usr/bin/java -> /usr/java/jre1.8.0_51
    
    ls -lad /etc/alternatives/java
    lrwxrwxrwx. 1 root root 20 Jul 21  2015 /etc/alternatives/java -> /usr/java/glassfish4
    

    after commenting out JAVA_HOME in tomcat.conf

    /etc/rc.d/init.d/tomcat start
    Starting tomcat:                                           [  OK  ]
    sudo service tomcat status
    tomcat (pid 13517) is running...                           [  OK  ]
    
    • ALex_hha
      ALex_hha over 8 years
      Could you run 'whereis java' and show the output?
    • Roy Hinkley
      Roy Hinkley over 8 years
      @ALex_hha see edit.
    • ALex_hha
      ALex_hha over 8 years
      and 'ls -lad /usr/bin/java' and '/etc/alternatives/java'
    • Roy Hinkley
      Roy Hinkley over 8 years
      @ALex_hha updated edit
    • user9517
      user9517 over 8 years
      Your JAVA_HOME does not seem to match your installed JAVA.
    • ALex_hha
      ALex_hha over 8 years
      comment JAVA_HOME in the /etc/tomcat/tomcat.conf and then run 'JAVA_HOME=/usr/java/jre1.8.0_51 bash -x /usr/sbin/tomcat version'
    • Roy Hinkley
      Roy Hinkley over 8 years
      @ALex_hha Please see pastebin.com/tYtxjwiU
    • Roy Hinkley
      Roy Hinkley over 8 years
      @ALex_hha Please move your comments to answer.
    • user9517
      user9517 over 8 years