Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass the -D additional parameter while starting tomcat?

I have a maven project, after running command mvn install all project as well as module compile and copied to local repository successfully. But now I want to run the generated web application in tomcat6. Client provided some parameter for tomcat like -Dapp.username,-Dapp.username, which will be used internally once project will start.ButI do not know how to set these additional parameter in tomcat6. Below is my development environment

  1. OS = Windows
  2. Tomcat = tomcat 6.0.27

Please help me?

like image 255
Rais Alam Avatar asked Feb 20 '13 15:02

Rais Alam


2 Answers

For Tomcat 6 you should add the params to the startup.sh (Windows startup.bat). For Tomcat 7 and above you should set the parameters in the {Catalina Root}/bin/setenv.sh like such:

export CATALINA_OPTS="$CATALINA_OPTS -Dapp.username=username -Dapp.password=password" 

Or in Windows:

set CATALINA_OPTS="$CATALINA_OPTS -Dapp.username=username -Dapp.password=password" 

NOTE: Notice the $CATALINA_OPTS at the beginning so you don't wipe out any previously set values. Not doing so can create a very hard to debug problem!

If the parameters you are setting are solely to be used by Tomcat then be sure to set it using CATALINA_OPTS.

If your application will be using the parameters then be sure to use JAVA_OPTS instead. Tomcat will also read these parameters. This can also go in the setenv.sh file. For instance:

export JAVA_OPTS="$JAVA_OPTS -Dapp.username=username -Dapp.password=password" 

Or in Windows:

set JAVA_OPTS="$JAVA_OPTS -Dapp.username=username -Dapp.password=password" 
like image 59
DavidR Avatar answered Sep 28 '22 23:09

DavidR


You can set an environment variable to do that. E.g. in Linux:

export JAVA_OPTS="-Dapp.username -Dapp.username"

Or in Windows:

set JAVA_OPTS="-Dapp.username -Dapp.username"

Do this before starting Tomcat

like image 39
betomontejo Avatar answered Sep 29 '22 00:09

betomontejo