Search code examples
batch-filetomcat7java-opts

How can I start tomcat by .bat and add JAVA_OPTS


set JAVA_HOME=
echo deploy web service ......
set CATALINA_HOME=%WEBTIER_HOME%
call "%CATALINA_HOME%\bin\service.bat" install %webtier%
"%CATALINA_HOME%\bin\tomcat7.exe" //US//%webtier% ++JvmOptions "-Djava.library.path=%installdir%\bin;-XX:MaxPermSize=256M;-Xms256m;-Xmx1024M"
set CATALINA_HOME=%WEBSERVICE_HOME%
call "%CATALINA_HOME%\bin\service.bat" install %webservice%
"%CATALINA_HOME%\bin\tomcat7.exe" //US//%webservice% ++JvmOptions "-Djava.library.path=%installdir%\bin;-XX:MaxPermSize=256M;-Xms256m;-Xmx1024M"

This is .bat file to start java web service,but there is error about memory leak and heap, so I want to set JAVA_OPTS,can I direct add "set JAVA_OPTS=-server -Xmx1024m" like

set JAVA_HOME=
set JAVA_OPTS=-server -Xmx1024m
echo deploy web service ......
set CATALINA_HOME=%WEBTIER_HOME%
call "%CATALINA_HOME%\bin\service.bat" install %webtier%
"%CATALINA_HOME%\bin\tomcat7.exe" //US//%webtier% ++JvmOptions "-Djava.library.path=%installdir%\bin;-XX:MaxPermSize=256M;-Xms256m;-Xmx1024M"
set CATALINA_HOME=%WEBSERVICE_HOME%
call "%CATALINA_HOME%\bin\service.bat" install %webservice%
"%CATALINA_HOME%\bin\tomcat7.exe" //US//%webservice% ++JvmOptions "-Djava.library.path=%installdir%\bin;-XX:MaxPermSize=256M;-Xms256m;-Xmx1024M"

or add after -Djava.library.path as JvmOptions parameters


Solution

  • Servers append the JAVA_OPTS environment variable to the call that executes the java command. So, you need to SET JAVA_OPTS before the call statement i.e.

    set JAVA_OPTS=-Xms512M -Xmx1024M
    
    call "%CATALINA_HOME%\bin\service.bat" install %webtier%"%CATALINA_HOME%\bin\tomcat7.exe" //US//%webtier% ++JvmOptions "-Djava.library.path=%installdir%\bin;-XX:MaxPermSize=256M;-Xms256m;-Xmx1024M"