且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Windows 7 上向 tomcat 添加 jvm 选项

更新时间:2023-12-06 13:07:52

创建文件 bin/setenv.bat.如果您使用 bin/startup.batbin/catalina.bat 来启动 Tomcat,那么 setenv 脚本将在执行大多数其他操作.您可以通过设置 CATALINA_OPTS 环境变量来设置您想要的任何 JVM 选项.

Create the file bin/setenv.bat. If you are using bin/startup.bat or bin/catalina.bat to start Tomcat, then the setenv script will be run before performing most other operations. You can set whatever JVM options you want by setting the CATALINA_OPTS environment variable.

如果您使用 Microsoft Windows 服务面板中的 Tomcat 服务启动器来启动 Tomcat,则您不能使用此技术.相反,您需要使用适当的 您可以在此处找到的选项.

If you are using Tomcat's service launcher from Microsoft Windows' services panel to launch Tomcat then you cannot use this technique. Instead, you'll need to run tomcat7.exe with the appropriate options you can find here.

请注意,您也可以设置 JAVA_OPTS,但 JAVA_OPTS 将用于所有 JVM 进程,包括启动请求关闭 Tomcat 的进程.例如,如果你想为Tomcat启用RMI服务,并且在JAVA_HOME中设置,那么Tomcat会正常启动,但是当尝试关闭时,由于端口冲突,关闭过程可能会失败.同样,如果您需要 20GiB 的 Tomcat 堆,并且您在 JAVA_OPTS 中设置了 -Xms-Xmx,您最终将创建一个 20GiB停止 Tomcat 进程的堆.因此,除非您有充分的理由使用 JAVA_OPTS,否则请使用 CATALINA_OPTS.

Note that you can also set JAVA_OPTS but JAVA_OPTS will be used for all JVM processes, including the one launched to request a shutdown of Tomcat. For example, if you want to enable RMI services for Tomcat and you set them in JAVA_HOME, then Tomcat will start up properly but when attempting to shutdown, the shutdown process may fail due to port conflicts. Similarly, if you need a 20GiB heap for Tomcat and you set -Xms and -Xmx in JAVA_OPTS, you'll end up creating a 20GiB heap for the process that stops Tomcat. So, use CATALINA_OPTS unless you have a very good reason to use JAVA_OPTS.