Solution to "java.net.BindException: Address already in use" error?

enter image description hereClick on the skull icon after stopping server to kill all associated processes. This should help in resolving the port issue.


This is due to JMX monitoring the Tomcat instance. Tomcat will be running on port 9999 so when JMX wants to start to check for the shutdown it can't bind to this port.

One way to fix this is to define your CATALINA_OPTS environment variable.

Setting these properties in JAVA_OPTS tries to start a jmx server when you start tomcat AND when you shutdown tomcat. Hence the port already in use exception. You need to set these properties for CATALINA_OPTS instead of JAVA_OPTS. This will only run when you start tomcat.

CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8999"
CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"

What fixes it for me is in $HOME/.bashrc I add this export:

export CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8999"

Credit: https://bowerstudios.com/node/636