Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How create environment variable for tomcat?

I'm trying create environment variable in tomcat 8 for my project, I need use this variable for choice properties logger. I read about setenv.sh and i create this file, but when i run my project - it does not run. How me create environment variable for check my project? I read about setenv in this site. I use ubuntu 14.04.

setenv.sh

JAVA_HOME="/usr/lib/jvm/java-8-oracle"
export JAVA_HOME

JAVA_OPTS="-Xmx4096m -Xms512m -server"
export JAVA_OPTS

CATALINA_HOME="/opt/tomcat"
export CATALINA_HOME
like image 243
Bohdan Olehovich Avatar asked Sep 29 '15 14:09

Bohdan Olehovich


People also ask

Where are Tomcat environment variables stored?

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. bat (on Windows) or setenv.sh (on *nix). The file has to be readable.

How do I set an environment variable in shell?

You can set your own variables at the command line per session, or make them permanent by placing them into the ~/. bashrc file, ~/. profile , or whichever startup file you use for your default shell. On the command line, enter your environment variable and its value as you did earlier when changing the PATH variable.


3 Answers

Please do the following. It'll work for you.

   1 sudo su and cd to /var/lib/tomcat8/bin/
   2 touch setenv.sh(if it doesn't exist)
   3 chmod 777 setenv.sh
   4 vim setenv.sh and set following line in setenv.sh
       export varriable=value
   5 sudo service tomcat8 restart 

and Enjoy...!!

like image 92
Raushan Avatar answered Sep 22 '22 11:09

Raushan


Rather than create /usr/share/tomcat8/bin/setenv.sh, you can put those settings in /etc/default/tomcat8.

I've found that setting JAVA_HOME in setenv.sh causes tomcat8 to not start up properly if it doesn't match what /etc/init.d/tomcat8 comes up with. The init.d script ignores setenv.sh but needs to know which java version is used so that it can check the process list to see if tomcat is running. The init.d script does use /etc/default/tomcat8, so it makes sense to delete setenv.sh and just put the settings in /etc/default.

like image 23
Stephen Ostermiller Avatar answered Sep 20 '22 11:09

Stephen Ostermiller


There is an alternate way if we're using eclipse:

  1. Go to Servers tab
  2. Double click on the server
  3. Click Open launch configuration
  4. Go to Environment tab
  5. Click New and set the key-value pair of environment variables
like image 44
Raman Sahasi Avatar answered Sep 23 '22 11:09

Raman Sahasi