1

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.

lucasvc
  • 107
  • 5
user1372488
  • 121
  • 1
  • 1
  • 9

4 Answers4

2

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.

Halfgaar
  • 8,084
  • 6
  • 45
  • 86
Mark Thomas
  • 887
  • 5
  • 8
1

If you have installed Tomcat from packages, you have to modify JAVA_OPTS in the file

/etc/default/tomcat...
lazzio
  • 306
  • 1
  • 2
  • 11
0

Do you have anything running on port 5555? You can try running

lsof -i :5555 or netstat -tulpn | grep :\5555 

to see what's running on that port.

Halfgaar
  • 8,084
  • 6
  • 45
  • 86
Mugurel
  • 903
  • 1
  • 9
  • 17
0

Hi to make the answer further clear, I am adding the below.

I created a file setenv.sh under $CATALINA_HOME/bin/. The file content is as below.

JAVA_OPTS="-Dcom.sun.management.jmxremote=true \
                   -Dcom.sun.management.jmxremote.ssl=false \
                   -Dcom.sun.management.jmxremote.authenticate=false \
                   -Djava.rmi.server.hostname=192.168.40.10"

There is no need of adding the file setenv.sh in catalina.sh since by seeing the file in name of setenv.sh tomcat will accept the parameters automatically. Then I added a line in bold font as below in catalina.sh.

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
***export CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote.port=9090"***

This way we can avoid port conflict issue in Tomcat. Thanks.

Halfgaar
  • 8,084
  • 6
  • 45
  • 86