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.

4 Answers 4

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.

2
  • Hey, How setenv.sh file get called? I mean where its written/configured to execute setenv.sh or we have write some for the same. Coz I have created the file as you said but nothing happens. Nov 3, 2014 at 11:33
  • It is called from catalina.sh Nov 5, 2014 at 14:08
1

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

/etc/default/tomcat...
4
  • But if I modify JAVA_OPTS then while stopping tomcat service I got error like java.rmi.server.ExportException : Port already in use: Nov 3, 2014 at 6:27
  • 1
    CATALINA_OPTS, not JAVA_OPTS Nov 5, 2014 at 14:08
  • Yeas use the /etc/default/tomcat file and use CATALINA_OPTS.
    – DevOps
    Dec 18, 2015 at 10:56
  • CATALINA_OPTS is for startup only but JAVA_OPTS is used for start AND stop
    – DevOps
    Dec 18, 2015 at 10:57
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.

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .