19

I'm manually running tomcat 6 as a windows service on the console. I need to change java_opts before starting it. How do I do that? Also, Is there a way I can see the logs dynamically?

Srinivas
  • 545
  • 5
  • 9
  • 16
  • Possible duplicate of [Passing JVM arguments to Tomcat when running as a service?](https://stackoverflow.com/questions/6225682/passing-jvm-arguments-to-tomcat-when-running-as-a-service) – Vadzim Apr 25 '19 at 15:59

5 Answers5

44

I know this is an old thread but needed to correct some assumptions.

Just an FYI, Catalina.bat is not utilized when running tomcat as a service. here is the method to change the JAVA_OPTS for tomcat running as a windows service.

  1. Open Services and click on the Tomcat service. Make a note of the service name (most likely Tomcat6).
  2. cd to the Tomcat bin directory
  3. Run the command

    tomcat6w //ES//Tomcat6 (substitute your service name if different)

  4. Click on the Java tab

  5. Add the options (each on a new line) to the Java Options box and set the initial and max memory to 1536 and 2048

    -XX:MaxPermSize=256m -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true

  6. Click apply

  7. Click on the general tab and restart the service
  • 1
    Thank you very much, exactly what i was looking for. Only minor edit, step 3 was **.\tomcat7w.exe //ES//** in my case, without **.exe** it didn't work. – Johannes Stadler Aug 29 '14 at 11:46
  • 4
    This should be the selected answer :) – manikanta Nov 10 '15 at 11:28
  • this should be the selected answer +1 also, this link has a way of scripting it, rather than manual. https://docs.lucee.org/guides/installing-lucee/windows/configuring-tomcat-as-a-windows-service.html – m1m1k Apr 22 '20 at 21:11
11

To change the settings, create a file named setenv.bat for windows or setenv.sh for Linux with entry as below:

Windows:

set JAVA_OPTS="-Xms256m -Xmx512m"

Linux:

export JAVA_OPTS="-Xms256m -Xmx512m"

Simply put this(setenv.bat/setenv.sh) file in %CATALINA_HOME%\bin\ folder. Your command file (catalina.bat/catalina.sh) already has a statement as below:

Windows:

if exist "%CATALINA_HOME%\bin\setenv.bat" call "%CATALINA_HOME%\bin\setenv.bat"

Linux:

if [ -r "$CATALINA_BASE/bin/setenv.sh" ]; then
 . "$CATALINA_BASE/bin/setenv.sh"

elif [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then . "$CATALINA_HOME/bin/setenv.sh" fi This will take care the rest.

Vivek Panday
  • 1,426
  • 2
  • 16
  • 34
1

You can set your JAVA_OPTS environment variable either manually via the command line prior to starting Tomcat:

set JAVA_OPTS=youropts

or you can edit catalina.bat with the values you want.

Chris
  • 22,923
  • 4
  • 56
  • 50
1

To alter the $JAVA_OPTS, you will probably need to edit the batch file you use to start Tomcat. I don't run Tomcat on Windows, but the $JAVA_OPTS appears in my catalina.sh inside the bin/ directory on my Linux installation.

As far as viewing logs dynamically on Windows, there are a couple of options I'm aware of.

  1. Download and install Cygwin, and then on the command-line, use tail -f logfilename like you would in Linux.
  2. Get the BearTail program and use that to follow your log files.
Mike
  • 7,994
  • 5
  • 35
  • 44
  • This solution for JAVA_OPTS specifically does not work when Tomcat is ran as a **Windows Service**. See Kelly P Fitzgerald's answer, which actually works (tested on a Tomcat 8/Windows Server 2008). – cmousset Mar 13 '20 at 19:55
0

In windows, cut the quotes on the set command. Quotes are taken literally.

Paul
  • 1