42

I am trying to run Tomcat 7 as a Windows Service (XP and Windows 7).

I see places to set the -Xmx and -Xms jvm args in catalina.bat, but I'm not sure how to do it when using $CATALINA_HOME/bin/service.bat install service-name. I looked around but the best I could find was that I needed to update windows registry key, though I'm not sure which one to edit.

I'm hoping there's an easier way, is there?

Update: I'm not using the windows installer mainly because I'm running multiple instances of tomcat on the same machine but with different ports (for reasons I'd rather not go into here). If I can use the installer with multiple instances using different ports, then I'd like to know how, but regardless, is it possible to do increase the memory on a tomcat windows service without the UI tools that come with the installer?

Franky
  • 259
  • 1
  • 5
Franky
  • 431
  • 2
  • 5
  • 4

6 Answers6

53

Assuming that you've downloaded and installed Tomcat as Windows Service Installer exe file from the Tomcat homepage, then check the Apache feather icon in the systray (or when absent, run Monitor Tomcat from the start menu). Doubleclick the feather icon and go to the Java tab. There you can configure the memory.

enter image description here

Restart the service to let the changes take effect.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Hai @BalusC, **1.** I want to add the `-XX:MaxPermSize`. If i do like above as u said, is it enough? And also **2.** I want to add `-XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled` to catalina batch script. How can I? please guide me... – vissu May 29 '12 at 14:49
  • 3
    @vissu: If you have new questions, press `Ask Question` button in right top. – BalusC May 29 '12 at 14:50
  • I changed this and save.But when I try to start it again, the tomcat is not being started. Once I change back to default memory size, I am able to start tomcat again. – Ankita Mar 10 '15 at 13:07
  • Or you can just run .\bin\tomcat7w.exe , even if you did not use the installation package. – Jose Gómez Mar 31 '16 at 11:07
  • The same dialog can be opened by running `%CATALINA_HOME%\bin\tomcatXw.exe`, where X is major version number. See also https://tomcat.apache.org/tomcat-7.0-doc/windows-service-howto.html – Vadzim Jan 22 '19 at 13:29
20

The answer to my own question is, I think, to use tomcat7.exe:

cd $CATALINA_HOME
.\bin\service.bat install tomcat
.\bin\tomcat7.exe //US//tomcat7 --JvmMs=512 --JvmMx=1024 --JvmSs=1024

Also, you can launch the UI tool mentioned by BalusC without the system tray or using the installer with tomcat7w.exe

.\bin\tomcat7w.exe //ES//tomcat

An additional note to this:

Setting the --JvmXX parameters (through the UI tool or the command line) may not be enough. You may also need to specify the JVM memory values explicitly. From the command line it may look like this:

bin\tomcat7w.exe //US//tomcat7 --JavaOptions=-Xmx=1024;-Xms=512;..

Be careful not to override the other JavaOption values. You can try updating bin\service.bat or use the UI tool and append the java options (separate each value with a new line).

Kdeveloper
  • 13,679
  • 11
  • 41
  • 49
Franky
  • 259
  • 1
  • 5
  • 1
    You can find more of these options here http://www.directory.utk.edu/docs/windows-service-howto.html Also you may need to quote the command line options if they have special characters in them (like when you set a path to javaagent for instance.) One more thing to note, is you can use `++JvmOptions=...` to append it to the list instead of -- which removes everything else. – Bob Apr 08 '16 at 21:50
  • the ++JvmOptions is safer and enough in most cases, be careful with the --JvmOptions one – Yampeku Jul 08 '16 at 11:56
7

//ES/tomcat -> This may not work if you have changed the service name during the installation.

Either run the command without any service name

.\bin\tomcat7w.exe //ES

or with exact service name

.\bin\tomcat7w.exe //ES/YourServiceName
iDev
  • 23,310
  • 7
  • 60
  • 85
bkumar
  • 71
  • 1
  • 1
5

According to catalina.sh customizations should always go into your own setenv.sh (or setenv.bat respectively) eg:

CATALINA_OPTS='-Xms512m -Xmx1024m'

My guess is that setenv.bat will also be called when starting a service.I might be wrong, though, since I'm not a windows user.

johanneslink
  • 4,877
  • 1
  • 20
  • 37
3

If you are running a custom named service, you should see two executables in your Tomcat/bin directory
In my case with Tomcat 8

08/14/2019  10:24 PM           116,648 Tomcat-Custom.exe
08/14/2019  10:24 PM           119,720 Tomcat-Customw.exe
               2 File(s)        236,368 bytes

Running the "w" terminated executable will let you configure Xmx in the Java tab
enter image description here

MonoThreaded
  • 11,429
  • 12
  • 71
  • 102
  • This screen is helpful but I needed to use @bkumar's command to open it. The full command is `tomcat7w.exe //ES/MyServiceNameOnTaskManager` – MK Yung Jul 27 '20 at 09:06
  • @MKYung you can also open the above tomcat properties by going into the bin folder of your installed/extracted tomcat folder, and executing tomcat7w.exe (Sample path: C:\tomcat\bin\tomcat7w.exe) – Rushikesh Gaidhani Nov 12 '21 at 04:16
0

For Tomcat 7 to increase memory :

Identify your service name, you will find it in the service properties, under the "Path to executable" at the end of the line

For me it is //RS//Tomcat70 so the name is Tomcat70

Then write as administrator :

tomcat7.exe //US//Tomcat70 --JvmOptions=-Xmx1024M
jpprade
  • 3,497
  • 3
  • 45
  • 58