5

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?

jww
  • 83,594
  • 69
  • 338
  • 732
Mr Mikkél
  • 2,377
  • 4
  • 26
  • 50
  • 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 ./.bashrc` – Nick Humrich May 12 '14 at 21:57
  • Also, you might want to add the export line to your catalina.sh file as well – Nick Humrich May 12 '14 at 22:00
  • Does the script run as your current user or as another user (root, tomcat, etc)? – JohnFullard May 12 '14 at 22:14
  • @Humdinger - yes, I've restarted the server and echoed $JAVA_HOME. It echoed as desired, but it still doesn't like it. – Mr Mikkél May 13 '14 at 18:19

2 Answers2

3

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
Hari
  • 927
  • 2
  • 13
  • 21
kenorb
  • 118,428
  • 63
  • 588
  • 624
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 :)

vkg
  • 1,789
  • 12
  • 15
  • 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... – Mr Mikkél May 13 '14 at 18:09
  • @MrA not sure what you mean by gets lost. You mean your tomcat configs gets lost? – vkg May 13 '14 at 18:11
  • 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... – Mr Mikkél May 13 '14 at 18:15
  • 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 – Nick Humrich May 13 '14 at 18:20
  • @Humdinger - would you guess that to be located somewhere in the project or somewhere on the server filespace? – Mr Mikkél May 13 '14 at 18:21
  • @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. – Nick Humrich May 13 '14 at 18:37
  • Method 2 is INCORRECT. The JAVA_HOME directory should be the base directory of the installation, NOT the "bin" directory. – Stephen C Sep 23 '18 at 05:07