Java.. and things in its ecosystem… tend to be inspirational. For instance I recently had to use Tomcat to deploy and test a few applications. One of those required more than 128MB of heap memory. Yes, by default, Tomcat 7 loads up with a Java heap size limited to 128MB. So, increasing it should be easy, right? Just a few clicks away in the documentation on the official site, right?
In 2012, Tomcat does not seem have a configuration file in which this can be edited (when I Google for something more than 15min, and don’t find it.. it probably doesn’t exist).
So people tend to hack the catalina.sh script, that is used to start the server up. Which is wrong. The right way is to put all the customizations into a setenv.sh file – in the same folder as catalina.sh. Of course. Server configuration through shell script variables. Such intuitiveness and yet it’s the last place anyone would look. Of course, sarcasm…
So.. find your catalina.sh, create setenv.sh in the same directory and write something like this into it:
export JAVA_OPTS=”-Xms256m -Xmx1024m”
This will set initial heap size to 256MB, and maximum to 1024MB. And there you have it. Additional usable shell variables, uh.. I mean configuration options, are listed in the beginning of the catalina.sh, commented out with descriptions.