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?
问题:
回答1:
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
回答2:
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
Or this: https://stackoverflow.com/search?q=setenv.sh