Tomcat : Where to configure jmx JAVA_OPTS or CATALINA_OPTS

jmxtomcat

I have Tomcat installed on ubuntu. I want to enable JMX for monitoring so in catalina.sh I modified JAVA_OPTS as:

JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=4998 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"

After restarting JMX is working but when I want to stop tomcat It gives error as:

Error: Exception thrown by the agent : java.rmi.server.ExportException
: Port already in use: 5555;nested exception is:
java.net.BindException: Address already in use:

After some Google search I come to know that we have write all JMX configurations to CATALINA_OPTS but after writing all configurations inside CATALINA_OPTS I am not able to connect.

Best Answer

Create a file alongside catalina.sh called setenv.sh. That way all your changes are in a separate file.

Use CATALINA_OPTS rather than JAVA_OPTS since CATALINA_OPTS is only used on start whereas JAVA_OPTS is used on start and stop.