如何在命令行上传递 tomcat 端口号? [英] How to pass tomcat port number on command line?

查看:40
本文介绍了如何在命令行上传递 tomcat 端口号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以告诉 tomcat 使用特定端口而不是 server.xml 中指定的端口?或者在 server.xml 中将环境变量配置为端口号的方法?(我可以在启动 tomcat 的批处理文件中设置)

Is it possible to tell tomcat to use a particular port instead of the one specified in server.xml? Or a way to configure an environment variable as port number in server.xml? (which I can set in a batch file which starts tomcat)

本质上,我想启动一个 tomcat 实例的不同副本(版本),而不必手动更改每个副本中的 server.xml,也不必记住哪个副本将在哪个端口启动.我希望在启动时指定端口号,以便在多个实例中不发生冲突.

Essentially, I want to launch different copies (versions) of a tomcat instance without having to manually change the server.xml in each of them and having to remember which one would launch at which port. I wish to specify the port number when I launch it so that there is no conflict in the multiple instances.

推荐答案

更改您的 server.xml,使其使用从属性扩展的端口号,而不是硬编码的端口号:

Change your server.xml so that it will use port numbers expanded from properties instead of hardcoded ones:

<Server port="${port.shutdown}" shutdown="SHUTDOWN">
...
  <Connector port="${port.http}" protocol="HTTP/1.1"/>
...
</Server>

以下是在 Linux 中启动的方法(假设您的当前目录是 CATALINA_HOME):

Here's how you can start in Linux (assuming your current directory is CATALINA_HOME):

JAVA_OPTS="-Dport.shutdown=8005 -Dport.http=8080" bin/startup.sh

在windows中应该是这样的:

In windows it should be smth like following:

set "JAVA_OPTS=-Dport.shutdown=8005 -Dport.http=8080"
bin\startup.bat

这篇关于如何在命令行上传递 tomcat 端口号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆