Search code examples
windows-servicesbatch-filetomcat6

Tomcat6 Service Setup; programatically concatenate JvmOptions using Batch File


This may bit a bit of a basic question, but I can't seem to find an answer on the web. I'm trying to automatically set up tomcat as a service through a batch file.

My batch file currently looks like this:

set memSize=512
set jvmOptions="-XX:MaxPermSize=512M"
ECHO Setting up tomcat as a service. 
call service.bat install
ECHO Setting the memory allocation to a maximum of %memSize%
ECHO Using JVM options %jvmOptions%
Tomcat6 //US// --JvmMx=%memSize%  --Startup="auto" --JvmOptions=%jvmOptions%

The issue I'm facing is that running the --JvmOptions switch overwrites all the current java options that are set in the tomcat6w.exe.

So my question is, does anyone know how to have the --JvmOptions switch concatenate the passed value to the end of the current value?

Thanks in advance


Solution

  • After a long hard search I did manage to find the answer in a code example. But then to make me feel very foolish I noticed that the answer was also here right under my nose on the Tomcat6 Windows Service How To page. By replacing the -- with ++ the option is concatenated rather than replacing the original.

    So the batch file became.

    set memSize=512
    set jvmOptions="-XX:MaxPermSize=512M"
    ECHO Setting up tomcat as a service. 
    call service.bat install
    ECHO Setting the memory allocation to a maximum of %memSize%
    ECHO Using JVM options %jvmOptions%
    Tomcat6 //US// --JvmMx=%memSize%  --Startup="auto" ++JvmOptions=%jvmOptions%
    

    Thanks.