在Tomcat中添加JVM选项

时间:2011-10-12 10:40:57

标签: tomcat jvm

如何在Apache Tomcat 6中添加jvm(Java虚拟机)选项?

tomcat中是否有管理控制台?我试过http://localhost:8080/admin,但我无法从中得到任何东西。

我想添加以下jvm选项:

-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

6 个答案:

答案 0 :(得分:31)

正如Bhavik Shah所说,你可以在JAVA_OPTS中做到,但推荐的方式(根据catalina.sh)是使用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.

答案 1 :(得分:22)

在[tomcat的路径] /bin/catalina.sh中的JAVA_OPTS变量中设置它。在Windows下有一个控制台,您可以在其中进行设置或使用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

答案 2 :(得分:18)

为此你需要运行" tomcat6w"应用程序是" bin"中标准Tomcat发行版的一部分。目录。例如。对于Windows,默认为" C:\ Program Files \ Apache Software Foundation \ Tomcat 6.0 \ bin \ tomcat6w.exe"。 " tomcat6w"应用程序启动GUI。如果你选择" Java"选项卡,您可以输入所有Java选项。

也可以通过命令行将JVM选项传递给tomcat。为此,您需要使用命令:

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

其中&#34; tomcatexecutable&#34;指的是你的tomcat应用程序,&#34; tomcatservicename&#34;是您正在使用的tomcat服务名称和&#34; JVMoptions&#34;是您的JVM选项。例如:

"tomcat6.exe" //US//tomcat6 ++JvmOptions="-XX:MaxPermSize=128m" 

答案 3 :(得分:15)

检查catalina.sh后(对于windows使用下面提到的所有内容的.bat版本)

#   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.

也是这个

#   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

所以在CATALINA_BASE / bin下创建一个setenv.sh(catalina.sh所在的同一目录)。编辑文件并将参数设置为CATALINA_OPTS

例如如果要更改堆大小,文件将如下所示

CATALINA_OPTS=-Xmx512m

或者在你的情况下,因为你使用的是windows setenv.bat

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

要稍后清除添加的选项,只需删除setenv.bat / sh

答案 4 :(得分:1)

如果你想在eclipse上设置jvm args,你可以在下面使用:

见下面两个完成它的链接:

  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
  3. 对于Tomcat,您可以在Tomcat的bin文件夹中创建一个setenv.bat文件,并在其下面添加以下行:

    echo "hello im starting setenv"
    set CATALINA_OPTS=-DNLP.home=${NLP.home} -Dhostname=${hostname}
    

答案 5 :(得分:0)

如果从startup.bat启动tomcat,则需要添加系统变量: JAVA_OPTS 作为名称和所需的参数(在您的情况下:

-agentpath:C:\ calltracer \ jvmti \ calltracer5.dll = traceFile-C:\ calltracer \ call.trace,filterFile-C:\ calltracer \ filters.txt,outputType-xml,使用不受控制 -Djava.library.path = C:\ calltracer \ jvmti -Dcalltracerlib = calltracer5