How to correct JAVA_HOME which should point to a JDK not a JRE folder? [duplicate]
Asked Answered
S

2

7

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?

Syneresis answered 12/5, 2014 at 21:54 Comment(4)
did your restart bash after you changed the settings? After changing the settings try echo $JAVA_HOME and see what it gives you. In order to reload settings you can try source ./.bashrcCoral
Also, you might want to add the export line to your catalina.sh file as wellCoral
Does the script run as your current user or as another user (root, tomcat, etc)?Buke
@Humdinger - yes, I've restarted the server and echoed $JAVA_HOME. It echoed as desired, but it still doesn't like it.Cow
C
7

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
Curlpaper answered 9/4, 2015 at 20:23 Comment(0)
I
0

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 :)

Immoral answered 12/5, 2014 at 22:13 Comment(7)
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...Cow
@MrA not sure what you mean by gets lost. You mean your tomcat configs gets lost?Immoral
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...Cow
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 folderCoral
@Humdinger - would you guess that to be located somewhere in the project or somewhere on the server filespace?Cow
@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.Coral
Method 2 is INCORRECT. The JAVA_HOME directory should be the base directory of the installation, NOT the "bin" directory.Belicia

© 2022 - 2024 — McMap. All rights reserved.