[英]Setting JAVA_OPTS while installing Tomcat as windows service
I am running multiple Tomcat
instances on the same host and have installed them as windows services.我在同一台主机上运行多个
Tomcat
实例,并将它们安装为 Windows 服务。 Of course this is with distinct ports for each of the Tomcat
instances.当然,这是针对每个
Tomcat
实例的不同端口。 Now I am trying to extract the port numbers out of server.xml
file and trying to pass them as JVM options, so that the server.xml
file looks the same for all the Tomcat
instances.现在我试图从
server.xml
文件中提取端口号并尝试将它们作为 JVM 选项传递,以便server.xml
文件对于所有Tomcat
实例看起来都相同。 Currently the Connector port in my server.xml
file for each instance looks like:目前,我的
server.xml
文件中每个实例的连接器端口如下所示:
Instance 1实例 1
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
Instance 2实例2
<Connector port="8180" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
and I am trying to make it look like我试图让它看起来像
<Connector port="${port.http}" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
As mentioned in this answer , I can edit the options manually to add the parameter -Dport.http=8080
or -Dport.http=8180
and it works fine, but what I need is this JVM option to be set when Tomcat
is installed as a windows service.正如在这个答案中提到的,我可以手动编辑选项以添加参数
-Dport.http=8080
或-Dport.http=8180
并且它工作正常,但我需要的是在安装Tomcat
时设置这个 JVM 选项一个窗口服务。
Below is the content of the .bat
file I am running to install Tomcat
instance1 as windows service (Its the same for instance2 except CATALINA_BASE, port and service name).以下是我运行以将
Tomcat
instance1 安装为 windows 服务的.bat
文件的内容(它与 instance2 相同,除了 CATALINA_BASE、端口和服务名称)。 As you see, I am also trying to set JAVA_OPTS
before it is installed as a service, but I don't seem to have any luck with this.如您所见,我还尝试在将
JAVA_OPTS
安装为服务之前对其进行设置,但我似乎对此没有任何运气。 I have also tried it with double-quotes like CALL SET "JAVA_OPTS=-Dport.http=8080"
and CALL SET JAVA_OPTS="-Dport.http=8080"
我也试过用双引号像
CALL SET "JAVA_OPTS=-Dport.http=8080"
和CALL SET JAVA_OPTS="-Dport.http=8080"
CALL SET JAVA_HOME=D:\Java
CALL SET CATALINA_BASE=D:\instance1
CALL SET JAVA_OPTS=-Dport.http=8080
CALL CD %CATALINA_HOME%\bin
service install instance1
Can anyone help please?有人可以帮忙吗?
If you want to set -D
options as states in the title than you are interested in --JvmOptions
https://tomcat.apache.org/tomcat-7.0-doc/windows-service-howto.html 如果您想将
-D
选项设置为标题中的状态,而不是对--JvmOptions
https://tomcat.apache.org/tomcat-7.0-doc/windows-service-howto.html感兴趣
eg 例如
Install the service named 'Tomcat7'
C:\> tomcat7 //IS//Tomcat7 --DisplayName="Apache Tomcat 7" ^
--Install="C:\Program Files\Tomcat\bin\tomcat7.exe" --Jvm=auto ^
--StartMode=jvm --StopMode=jvm ^
--JvmOptions -DwhateverHere
--StartClass=org.apache.catalina.startup.Bootstrap --StartParams=start ^
--StopClass=org.apache.catalina.startup.Bootstrap --StopParams=stop
Eventually I could resolve it by setting JvmArgs
in the batch file that I use to install 'Tomcat' as windows service. 最终,我可以通过在用于将“ Tomcat”安装为Windows服务的批处理文件中设置
JvmArgs
来解决该问题。 The content of my .bat
file looks like below: 我的
.bat
文件的内容如下所示:
CALL SET JAVA_HOME=D:\Java
CALL SET CATALINA_BASE=D:\instance1
CALL SET JAVA_OPTS=-Dport.http=8080
CALL SET JvmArgs=-Dport.http=8080;-Dport.shutdown=8005 // This line did the trick
CALL CD %CATALINA_HOME%\bin
service install instance1
I found this out when I was going through the code in service.bat
file to check how the JVM options are set and found %JvmArgs%
appended at the end as below: 当我查看
service.bat
文件中的代码以检查JVM选项的设置方式时发现了这一点,并发现%JvmArgs%
附加在末尾,如下所示:
--JvmOptions "-Dcatalina.home=%CATALINA_HOME%;-Dcatalina.base=%CATALINA_BASE%;-D%ENDORSED_PROP%=%CATALINA_HOME%\endorsed;-Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties;%JvmArgs%" ^
Hope this helps someone looking for a similar configuration :) 希望这可以帮助寻找相似配置的人:)
if you read carefully the details about jvmoptions in https://tomcat.apache.org/tomcat-7.0-doc/windows-service-howto.html you will see it says it does not work in exe mode.如果您仔细阅读https://tomcat.apache.org/tomcat-7.0-doc/windows-service-howto.html 中有关 jvmoptions 的详细信息,您会看到它说它在 exe 模式下不起作用。 I have confirmed this.
我已经证实了这一点。 Even if the value appears in tomcat6w it does not usable in catalina.properties .
即使该值出现在 tomcat6w 中,它也无法在 catalina.properties 中使用。 In fact, even tomcat 8 & 9 state the same thing.
事实上,即使是 tomcat 8 & 9 也声明了同样的事情。 I would be happy if somebody could prove me wrong.
如果有人能证明我错了,我会很高兴。 The quest continues....
探索仍在继续......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.