How to correct JAVA_HOME which should point to a J

2019-07-02 08:25发布

问题:

This question already has an answer here:

  • JAVA_HOME should point to a JDK not a JRE 16 answers

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?

回答1:

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 your JRE java paths, so your JDK path is the one without jre, for example:

JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64

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

JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 catalina.sh debug


回答2:

Method 1 Adding to bashrc will work.

Method 2 But I think a better way is to add it to catalina.sh

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

Method 3 And even a more cleaner way would be create a env_var.sh (assuming you created env_var.sh in same folder as catalina.h) file and then use the env_var.sh file in catalina.sh like this

source ./env_var.sh

Now you can throw your own environment specific settings in this new file and leave catalina.sh at peace. Advantage is you are not messing up catalina.sh and you not dependent on one particular users bash profile.

Simple Example of env_var.sh

#!/bin/sh
JAVA_OPTS="$JAVA_OPTS -server"
JAVA_OPTS="$JAVA_OPTS -Xms2096m"
JAVA_OPTS="$JAVA_OPTS -Xmx4096m"
JAVA_OPTS="$JAVA_OPTS -XX:PermSize=128m"
JAVA_OPTS="$JAVA_OPTS -XX:MaxPermSize=512m"

echo Using JAVA_OPTS settings $JAVA_OPTS

CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote"
CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote.port=[some_port]"

echo Using CATALINA_OPTS settings $CATALINA_OPTS
JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-i386

I hope it helps :)