38

How can I add jvm(Java virtual machine) options in Apache Tomcat 6?

Is there a administration console in tomcat? I tried http://localhost:8080/admin but I could not get anything out of it.

I want to add the following jvm options:

-agentpath:C:\calltracer\jvmti\calltracer5.dll=traceFile-C:\calltracer\call.trace,filterFile-C:\calltracer\filters.txt,outputType-xml,usage-uncontrolled -Djava.library.path=C:\calltracer\jvmti -Dcalltracerlib=calltracer5
abarisone
  • 3,429
  • 11
  • 27
  • 49
pavan
  • 635
  • 2
  • 10
  • 21

6 Answers6

36

As Bhavik Shah says, you can do it in JAVA_OPTS, but the recommended way (as per catalina.sh) is to use CATALINA_OPTS:

#   CATALINA_OPTS   (Optional) Java runtime options used when the "start",
#                   "run" or "debug" command is executed.
#                   Include here and not in JAVA_OPTS all options, that should
#                   only be used by Tomcat itself, not by the stop process,
#                   the version command etc.
#                   Examples are heap size, GC logging, JMX ports etc.

#   JAVA_OPTS       (Optional) Java runtime options used when any command
#                   is executed.
#                   Include here and not in CATALINA_OPTS all options, that
#                   should be used by Tomcat and also by the stop process,
#                   the version command etc.
#                   Most options should go into CATALINA_OPTS.
Mitch1077487
  • 701
  • 6
  • 8
26

Set it in the JAVA_OPTS variable in [path to tomcat]/bin/catalina.sh. Under windows there is a console where you can set it up or you use the catalina.bat.

JAVA_OPTS=-agentpath:C:\calltracer\jvmti\calltracer5.dll=traceFile-C:\calltracer\call.trace,filterFile-C:\calltracer\filters.txt,outputType-xml,usage-uncontrolled -Djava.library.path=C:\calltracer\jvmti -Dcalltracerlib=calltracer5
Bhavik Shah
  • 4,765
  • 2
  • 21
  • 39
morja
  • 7,779
  • 2
  • 31
  • 51
  • 13
    At least in Tomcat 7, this is not the recommended place for customisations. From `catalina.sh`: "Do not set the variables in this script. Instead put them into a script setenv.sh in CATALINA_BASE/bin to keep your customizations separate". Also, as Mitch notes, `CATALINA_OPTS` is the more canonical variable to store this in. – Andy MacKinlay Jun 05 '14 at 03:48
  • 3
    To expand on setenv.sh, here is an example entry: `export CATALINA_OPTS="$CATALINA_OPTS -XX:MaxPermSize=256m"` (this would increase max perm size). – whla Aug 12 '16 at 19:38
21

For this you need to run the "tomcat6w" application that is part of the standard Tomcat distribution in the "bin" directory. E.g. for windows the default is "C:\Program Files\Apache Software Foundation\Tomcat 6.0\bin\tomcat6w.exe". The "tomcat6w" application starts a GUI. If you select the "Java" tab you can enter all Java options.

It is also possible to pass JVM options via the command line to tomcat. For this you need to use the command:

<tomcatexecutable> //US//<tomcatservicename> ++JvmOptions="<JVMoptions>"

where "tomcatexecutable" refers to your tomcat application, "tomcatservicename" is the tomcat service name you are using and "JVMoptions" are your JVM options. For instance:

"tomcat6.exe" //US//tomcat6 ++JvmOptions="-XX:MaxPermSize=128m" 
Paul Jansen
  • 1,066
  • 1
  • 10
  • 32
  • This will mean that tomcat will always have to be started as a service for the changes to take effect, hence the first approach should be better – frewper Mar 19 '14 at 12:14
  • ``` ` Function AppendTomcatJavaOptions1([string]$TomcatBin, [string]$Options) { # In this case we're taking advantage of the fact that we named the service the same as the /bin/tomcat.exe # but if your service name is different, you may need to modify this. $cmd = """$TomcatBin\$($TomcatServiceName).exe"" //US//$TomcatServiceName ++JvmOptions=$Options" Write-Host "Appending Java Options via Service option: $cmd" cmd.exe /C "$cmd" }` ``` – m1m1k May 04 '20 at 21:11
19

After checking catalina.sh (for windows use the .bat versions of everything mentioned below)

#   Do not set the variables in this script. Instead put them into a script
#   setenv.sh in CATALINA_BASE/bin to keep your customizations separate.

Also this

#   CATALINA_OPTS   (Optional) Java runtime options used when the "start",
#                   "run" or "debug" command is executed.
#                   Include here and not in JAVA_OPTS all options, that should
#                   only be used by Tomcat itself, not by the stop process,
#                   the version command etc.
#                   Examples are heap size, GC logging, JMX ports etc

So create a setenv.sh under CATALINA_BASE/bin (same dir where the catalina.sh resides). Edit the file and set the arguments to CATALINA_OPTS

For e.g. the file would look like this if you wanted to change the heap size

CATALINA_OPTS=-Xmx512m

Or in your case since you're using windows setenv.bat would be

set CATALINA_OPTS=-agentpath:C:\calltracer\jvmti\calltracer5.dll=traceFile-C:\calltracer\call.trace,filterFile-C:\calltracer\filters.txt,outputType-xml,usage-uncontrolled -Djava.library.path=C:\calltracer\jvmti -Dcalltracerlib=calltracer5

To clear the added options later just delete setenv.bat/sh

FearlessHyena
  • 2,266
  • 27
  • 34
2

if you want to set jvm args on eclipse you can use below:

see below two links to accomplish it:

  1. eclipse setting to pass jvm args to java
  2. eclipse setting to pass jvm args to java and adding to run config on eclipse

And for Tomcat you can create a setenv.bat file in bin folder of Tomcat and add below lines to it :

echo "hello im starting setenv"
set CATALINA_OPTS=-DNLP.home=${NLP.home} -Dhostname=${hostname}
StackzOfZtuff
  • 1,671
  • 18
  • 19
Dean Jain
  • 1,477
  • 15
  • 12
1

If you start tomcat from startup.bat, you need to add a system variable :JAVA_OPTS as name and the parameters that you wants (in your case :

-agentpath:C:\calltracer\jvmti\calltracer5.dll=traceFile-C:\calltracer\call.trace,filterFile-C:\calltracer\filters.txt,outputType-xml,usage-uncontrolled -Djava.library.path=C:\calltracer\jvmti -Dcalltracerlib=calltracer5

aName
  • 1,865
  • 1
  • 18
  • 43