I am using the eclipse for web application coding. Within this I passed environment variable like :
APP_MASTER_PASSWORD
and its value.I can access this value in java code as System.getenv("APP_MASTER_PASSWORD")
.
But now I want to pass this environment variable to tomcat and access it in application instead of passing thru eclipse.
So how can I pass such variable to tomcat?
I googled about it. But I didn't get any solution.
Apart from CATALINA_HOME and CATALINA_BASE, all environment variables can be specified in the "setenv" script. The script is placed either into CATALINA_BASE/bin or into CATALINA_HOME/bin directory and is named setenv.
The CATALINA_HOME environment variable should be set to the location of the root directory of the "binary" distribution of Tomcat. The Tomcat startup scripts have some logic to set this variable automatically if it is absent, based on the location of the startup script in *nix and on the current directory in Windows.
The setenv. batcommand is used to modify or to set environment variables for the Tomcat application server. These setting only apply when using the catalina.
You can use setenv.bat or .sh to pass the environment variables to the Tomcat.
Create CATALINA_BASE/bin/setenv.bat or .sh file and put the following line in it, and then start the Tomcat.
On Windows:
set APP_MASTER_PASSWORD=foo
On Unix like systems:
export APP_MASTER_PASSWORD=foo
You should use System property instead of environment variable for this case. Edit your tomcat scripts for JAVA_OPTS and add property like:
-DAPP_MASTER_PASSWORD=foo
and in your code, write
System.getProperty("APP_MASTER_PASSWORD");
You can do this in Eclipse as well, instead of JAVA_OPTS, copy the line in VM parameters inside run configurations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With