java Windows下如何用特定的server.xml启动Tomcat?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1154668/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to start Tomcat with a specific server.xml under Windows?
提问by seb
I want to start Tomcat 6 with special configuration sometimes, not using the "server.xml". So I created another xml file named server_test.xml. Now I want to tell tomcat to use this configuration. How is this done?
有时我想以特殊配置启动 Tomcat 6,而不是使用“server.xml”。所以我创建了另一个名为 .xml 的 xml 文件server_test.xml。现在我想告诉tomcat使用这个配置。这是怎么做的?
I found nearly nothing searching the web. Only that: "Use different server.xml file in Tomcat configuration: ./tomcat.sh start -f /var/tmp/server-${USER}.xml"
我在网上几乎找不到任何东西。只有:“在Tomcat配置中使用不同的server.xml文件:./tomcat.sh start -f /var/tmp/server-${USER}.xml”
This is exactly what I want. Maybe this is working for linux systems but not for windows. Any ideas out there?
这正是我想要的。也许这适用于 linux 系统,但不适用于 Windows。有什么想法吗?
回答by seb
I've got it. I took me the half night, but it works :)
我懂了。我带了我半夜,但它有效:)
At first I also thought of symbolic links, but under Windows it's not a thing you would like to use. My second thought was modifying catalina.bat, but that's not that easy. And different CATALINA_HOME's is not what I really want.
起初我也想到了符号链接,但在 Windows 下它不是你想使用的东西。我的第二个想法是修改catalina.bat,但这并不容易。而不同CATALINA_HOME的不是我真正想要的。
So what have I done? I've provided the server.xmlas a parameter to catalina.bat.
那我做了什么?我已经提供了server.xml作为参数给catalina.bat.
catalina.bat start -config \conf\server_test.xml
Nice and easy :)
好,易于 :)
You can have a lot of server configuration files and provide the one you need to the start and stop script. The tricky thing was that the Catalina class gives you the wrong usage information :
您可以拥有许多服务器配置文件,并为启动和停止脚本提供所需的配置文件。棘手的是 Catalina 类为您提供了错误的使用信息:
usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] [ -nonaming ] { start | stop }
But if you exchange the parameters and first provide "start" or "stop" and then the "-config ..." argument, everything works.
但是,如果您交换参数并首先提供“开始”或“停止”,然后提供“ -config ...”参数,则一切正常。
Also very nice is that you can use this solution the create different run configuration in IntelliJ IDEA. I have one where the Tomcat connects to a local database and one connecting to a development database. For each I have a different server.xml.
同样非常好的是,您可以使用此解决方案在 IntelliJ IDEA 中创建不同的运行配置。我有一个 Tomcat 连接到本地数据库和一个连接到开发数据库的地方。对于每个我都有不同的server.xml.
I hope this helps.
我希望这有帮助。
Regards, Sebastian
问候, 塞巴斯蒂安
回答by matt b
It doesn't look like there is a (documented) option you can pass to startup.sh or catalina.sh to change this.
看起来没有(记录在案的)选项可以传递给 startup.sh 或 catalina.sh 来更改它。
Perhaps you can set server.xmlas a symlink to the file you actually want to use, and just change the symlink prior to starting the server when you want to change it?
也许您可以将server.xml符号链接设置为您实际要使用的文件,并在要更改它时在启动服务器之前更改符号链接?
Otherwise you can play around with using different values of $CATALINA_HOMEbut this would require you to duplicate the entire directory structures.
否则,您可以$CATALINA_HOME尝试使用不同的值,但这需要您复制整个目录结构。
回答by ChssPly76
tomcat.shhasn't existed since 3.x and, to be honest, I don't recall it having '-f' option back then either.
tomcat.sh从 3.x 开始就不存在了,老实说,我不记得当时它有 '-f' 选项。
You have two choices here:
您在这里有两个选择:
A) You can setup multiple tomcat instances as described hereand switch between them by pointing CATALINA_BASEto the one you want.
A) 您可以按照此处所述设置多个 tomcat 实例,并通过指向所需的实例在它们之间进行切换CATALINA_BASE。
B) You can create multiple server.xmlfiles named differently (e.g. server-1.xml, server-2.xml, etc...) and write a simple batch script that would copy the one you specify as command line argument to the actual server.xmland then start Tomcat.
B) 您可以创建多个server.xml不同命名的文件(例如server-1.xml,,server-2.xml等...)并编写一个简单的批处理脚本,该脚本会将您指定为命令行参数的文件复制到实际文件中server.xml,然后启动 Tomcat。

