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. Of course this is with distinct ports for each of the Tomcat instances....

问题:

I am running multiple Tomcat instances on the same host and have installed them as windows services. Of course this is with distinct ports for each of the Tomcat instances. 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. Currently the Connector port in my server.xml file for each instance looks like:

Instance 1

<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />

Instance 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.

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). 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. 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_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?


回答1:

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

eg

Install the service named 'Tomcat7'
C:> tomcat7 //IS//Tomcat7 --DisplayName="Apache Tomcat 7" ^
     --Install="C:Program FilesTomcatbintomcat7.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

回答2:

Eventually I could resolve it by setting JvmArgs in the batch file that I use to install 'Tomcat' as windows service. The content of my .bat file looks like below:

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:

--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%conflogging.properties;%JvmArgs%" ^

Hope this helps someone looking for a similar configuration :)

  • 发表于 2019-03-01 03:07
  • 阅读 ( 214 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除