在Tomcat中添加JVM选项

问题描述 投票:34回答:6

如何在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
tomcat jvm
6个回答
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.

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

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>"

其中“tomcatexecutable”指的是tomcat应用程序,“tomcatservicename”是您正在使用的tomcat服务名称,“JVMoptions”是您的JVM选项。例如:

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

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所在的dir)。编辑文件并将参数设置为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


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

对于Tomcat,您可以在Tomcat的bin文件夹中创建一个setenv.bat文件,并在其下面添加以下行:

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

0
投票

如果从startup.bat启动tomcat,则需要添加一个系统变量: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

© www.soinside.com 2019 - 2024. All rights reserved.