Tuesday, November 5, 2013

Using setenv.sh on tomcat6

If you want to set java runtime options for tomcat, a Java application, you can't do that in your web application, because by the time it gets called, the JVM has already been created and configured by Tomcat. So the Tomcat way around this is to let the user specify a shell script to be run from catalina.sh, which will be called to set CATALINA_OPTS, which will be passed to java. One of the gotchas associated with this method, however, is that catalina.sh, which is the script used by the OS on Linux to launch Tomcat uses the dash (/bin/sh) not the bash shell. If you, like foolish me, wrote your script in bash then it will not run. If you worse still invoke bash from within dash using a shebang #!/usr/bin/bash line the contents of your script will be ignored. So you have to write it in dash. I had to learn this the hard way, by tracing back uninformative error messages, and I don't want to forget it. So that is why I am recording it here.

No comments:

Post a Comment