I have a requirement to add -DAPP_ENCRYPTION_PASSWORD in Tomcat to start an application. Can any one point exactly where to add this parameter? And how?
2 Answers
The simple and preferred way to set environment variables for Tomcat is via the bin/setenv.sh
script. See this: How to tune Tomcat 5.5 JVM Memory settings without using the configuration program
-
How about in Tomcat 6? Is it the same? – Ahmed Dec 15 '11 at 17:40
-
1Yes, it is. Also in Tomcat 7. – jbindel Dec 15 '11 at 18:03
It all depends on how you plan to start Tomcat. Tomcat itself wants to be run a shell script that's typically located at $TOMCAT_HOME/bin/catalina.sh (there's an equivalent .bat file for windows). Inside of that file it describes what tomcat expects for an environment. If you want to get your -DAPP_ENCRYPTION_PASSWORD system property into the startup of Tomcat, I think you just figure out how to get it set up in the environment as JAVA_OPTS and you are on your way.
If you are desperate and want to avoid setting up the environment, I suppose that you could edit catalina.sh directly.
The environment variable sequence looks like...
- from a command shell, change to the directory where tomcat is deployed
- from a command shell, change to the "bin" directory under tomcat
- from a command shell, set the JAVA_OPTS evironment variable like "JAVA_OPTS=-DAPP_ENCRYPTION_PASSWORD"
- from a command shell, start tomcat like "./startup.sh"
The output will look like...
bobk-mbp:~ bobk$ cd work/apache-tomcat-6.0.35/
bobk-mbp:apache-tomcat-6.0.35 bobk$ cd bin
bobk-mbp:bin bobk$ JAVA_OPTS=-DAPP_ENCRYPTION_PASSWORD
bobk-mbp:bin bobk$ ./startup.sh
Using CATALINA_BASE: /Users/bobk/work/apache-tomcat-6.0.35
Using CATALINA_HOME: /Users/bobk/work/apache-tomcat-6.0.35
Using CATALINA_TMPDIR: /Users/bobk/work/apache-tomcat-6.0.35/temp
Using JRE_HOME: /Library/Java/Home
Using CLASSPATH: /Users/bobk/work/apache-tomcat-6.0.35/bin/bootstrap.jar

- 10,838
- 11
- 62
- 115
-
Half of the things you said was way over my head :D ... I think I will go for a desperation stuff. So how and where I have to add this param in Catalina.sh? And after that can you explain me of how to set it up in the environment as CATALINA_OPTS or JAVA_OPTS, so that I can be on my way ??? :) – Ahmed Dec 08 '11 at 01:10
-
JAVA_OPTS="$JAVA_OPTS -DAPP_ENCRYPTION_PASSWORD" added that right under the #!/bin/sh should probabaly do the trick. – Bob Kuhar Dec 08 '11 at 01:46
-
I really don't endorse this solution, though. The correct way is to get the environment variable set up. It is equally simple. Are you windows or unix? – Bob Kuhar Dec 08 '11 at 01:48
-
How are you running Tomcat? From a command line, you are typing in something like "./startup.sh" and shutting it down with something like "./shutdown.sh". Right? – Bob Kuhar Dec 08 '11 at 02:36
-
let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/5675/discussion-between-bob-kuhar-and-brat-rosm) – Bob Kuhar Dec 08 '11 at 02:52