How to correct JAVA_HOME which should point to a JDK not a JRE folder?

21,340

In Debian/Ubuntu run:

$ sudo update-alternatives --config java
Path                                          
---------------------------------------------
/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java
/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java

to find out the executables that are linked with your java command.

Note: when update-alternatives is used with the --config option, the expected goal is to manually set the executable linked with the command (for e.g., see here). For our purposes, we could use --query option instead.

The JDK paths are the prefix in these paths, i.e., the one before jre. For example, based on the above output, you could set JAVA_HOME in your .bashrc file:

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH

So you can either export this path or prefix before running the command, e.g.:

JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 catalina.sh debug
Share:
21,340
Mr Mikkél
Author by

Mr Mikkél

Updated on May 02, 2021

Comments

  • Mr Mikkél
    Mr Mikkél almost 3 years

    I'm trying to run Catalina on Ubuntu Linux using the debug command. I'm getting the following error:

    JAVA_HOME should point to a JDK in order to run in debug mode.
    /bin/sh died with exit status 1
    

    However, I have tried setting JAVA_HOME in the .bashrc to all of the following:

    export JAVA_HOME="/usr/lib/jvm/java-1.7.0-openjdk-i386/"
    export JAVA_HOME="/usr/lib/jvm/java-1.7.0-openjdk-i386"
    export JAVA_HOME="/usr/lib/jvm/java-1.7.0-openjdk-i386/jre/bin"
    export JAVA_HOME="/usr/lib/jvm/java-1.7.0-openjdk-i386/jre/bin/"
    

    Am I missing anything?

  • Mr Mikkél
    Mr Mikkél almost 10 years
    I appreciate the comments! Unfortunately I don't have control over the catalina.sh or anything in that folder. It's all built in the target directory, and gets lost when I do a clean on the project...
  • vkg
    vkg almost 10 years
    @MrA not sure what you mean by gets lost. You mean your tomcat configs gets lost?
  • Mr Mikkél
    Mr Mikkél almost 10 years
    I mean, the folder with the catalina.sh gets deleted and rebuilt. It's within the target directory. So, if I put stuff in there, it will disappear...
  • Nick Humrich
    Nick Humrich almost 10 years
    the target is just copied from a source. So you need to make the change wherever your source is located. Usually in a tomcat setting folder
  • Mr Mikkél
    Mr Mikkél almost 10 years
    @Humdinger - would you guess that to be located somewhere in the project or somewhere on the server filespace?
  • Nick Humrich
    Nick Humrich almost 10 years
    @MrA I dont quite remember.. but another way to do it is to change it in $CATALINA_HOME/bin/setenv.sh which should be on the server filespace for tomcat. Catalina calls that file when it runs.
  • Stephen C
    Stephen C over 5 years
    Method 2 is INCORRECT. The JAVA_HOME directory should be the base directory of the installation, NOT the "bin" directory.