Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change java_opts for tomcat when we run it as a windows service manually?

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?

like image 601
Srinivas Avatar asked Nov 21 '11 17:11

Srinivas


People also ask

How do I install Tomcat 9 as a service in Windows?

To install an instance, first set the CATALINA_HOME environment variable to the name of the Tomcat installation directory. Then create a second environment variable CATALINA_BASE and point this to the instance folder. Then run "service. bat install" command specifying a service name.


2 Answers

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
like image 71
Kelly P Fitzgerald Avatar answered Oct 18 '22 03:10

Kelly P Fitzgerald


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.

like image 43
Vivek Panday Avatar answered Oct 18 '22 01:10

Vivek Panday