运行 Tomcat8 在 windows 上使用 startup.bat 时的 JVM 选项

JVM Options while running Tomcat8 using startup.bat on windows

我想为我的应用程序提供一些 JVM 选项。该应用程序是一个 Web 应用程序,打包为 war。我正在使用 Tomcat8 来部署这个 war。我想在 运行ning tomcat 使用 statup.bat 文件时提供 JVM 选项。

我可以 运行 使用 eclipse 成功地应用程序。 eclipse 服务器配置提供使用启动配置提供 JVM 参数。

我尝试了以下提供 JVM 选项的方法。

  1. 通过命令 set JAVA_OPTS="........." 在 bin 目录中使用 setenv.bat。 示例 - 我分别在 setenv.bat 文件中尝试了以下命令。
    set JAVA_OPTS="-Ddp.registry.local=false -Ddp.registry.logon.id=dpconf -Ddp.registry.logon.pwd=password-Ddp.registry.host.address=ltest16.sto1.3s.intern -Ddp.registry.appid=1234 -Ddp.registry.execunit=BillingDataProvider -Ddp.registry.instance=bdp -Ddp.registry.instance.lowercase=bdp -Ddp.registry.host.port=3700 -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger -Djava.util.prefs.PreferencesFactory=com.smarttrust.common.mechanism.prefs.RegistryJasapPreferencesFactory -Ddp.log.root=C:/Users/dir/softools/apache-tomcat-8.0.5/logs -Ddp.server.log.root=C:/Users/dir/softools/apache-tomcat-8.0.5/logs -Dota.sc.log.root=C:/Users/dir/softools/apache-tomcat-8.0.5/logs -Dlog4j.configuration=file:C:/Users/dir/softools/apache-tomcat-8.0.5/logs/log4j.xml -Djava.util.logging.config.file=C:/Users/dir/softools/apache-tomcat-8.0.5/logs/bdp-log.properties"
    set CATALINA_OPTS="-Ddp.registry.local=false -Ddp.registry.logon.id=dpconf -Ddp.registry.logon.pwd=password -Ddp.registry.host.address=ltest16.sto1.3s.intern -Ddp.registry.appid=1234 -Ddp.registry.execunit=BillingDataProvider -Ddp.registry.instance=bdp -Ddp.registry.instance.lowercase=bdp -Ddp.registry.host.port=3700 -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger -Djava.util.prefs.PreferencesFactory=com.smarttrust.common.mechanism.prefs.RegistryJasapPreferencesFactory -Ddp.log.root=C:/Users/dir/softools/apache-tomcat-8.0.5/logs -Ddp.server.log.root=C:/Users/dir/softools/apache-tomcat-8.0.5/logs -Dota.sc.log.root=C:/Users/dir/softools/apache-tomcat-8.0.5/logs -Dlog4j.configuration=file:C:/Users/dir/softools/apache-tomcat-8.0.5/logs/log4j.xml -Djava.util.logging.config.file=C:/Users/dir/softools/apache-tomcat-8.0.5/logs/bdp-log.properties"
  1. 在 运行ning startup.bat 之前在命令提示符下导出 JAVA_OPTS,例如 set JAVA_OPTS="....."。以上命令在 运行ning startup.bat.

  2. 之前在命令提示符下导出
  3. 例如使用 context.xml 文件 -

        <context>
         .....................
        <Environment name="dp.registry.local" value="false" type="java.lang.String"/>
         ........................
        </context>

但运气不好。我不确定我在做什么错误。

推荐使用CATALINA_OPTS,见catalina.bat中的评论。

其次,VM选项需要单独加上前缀-D,例如:

Linux/Unix Shell:

CATALINA_OPTS="-Dcom.sun.management.jmxremote=true \
               -Dcom.sun.management.jmxremote.ssl=false \
               -Dcom.sun.management.jmxremote.authenticate=false \
               -Djava.rmi.server.hostname=192.168.40.10"

如评论中所述,windows 批处理中的多行转义字符是 ^,出于某种原因,无需添加双引号。

Windows bat/cmd

CATALINA_OPTS=-Dcom.sun.management.jmxremote=true ^
               -Dcom.sun.management.jmxremote.ssl=false ^
               -Dcom.sun.management.jmxremote.authenticate=false ^
               -Djava.rmi.server.hostname=192.168.40.10

问题在于双引号。从命令提示符导出时不要使用双轴。只需设置 JAVA_OPTS=-D..... -D.... Space 分隔的选项列表。

如果你从 catlina.bat 回显 java_opts ,它会给你一个清晰的画面。