Appearance
'How do I resolve the "java.net.BindException: Address already in use: JVM_Bind"
The java.net.BindException: Address already in use: JVM_Bind error occurs when you try to bind a socket to a local address and port, but the address and port are already in use by another process. This can happen when you try to start a server on a port that is already being used by another server, or when you try to bind a client socket to a local address and port that are already in use.
To fix this error, you need to find the process that is using the address and port and stop it, or choose a different address and port for your server or client.
Here are some steps you can follow to troubleshoot the BindException error:
Use the
netstatcommand to find out which process is using the address and port. On Windows, open a command prompt and run:cmdnetstat -aon | findstr :<port>On Linux, run:
bashnetstat -anp | grep :<port>On macOS,
netstatdoes not support the-pflag. Instead, uselsof:bashlsof -i :<port>This will show you a list of active connections and the PID of the process using each connection.
Identify the process name using the PID. On Windows, run:
cmdtasklist /fi "PID eq <pid>"On Linux or macOS, run:
bashps -p <pid> -o pid,commStop the process that is using the address and port.
- On Windows, run:cmd
taskkill /pid <pid> /f - On Linux or macOS, run:bashIf the process does not terminate, you may need to force it with
kill <pid>kill -9 <pid>. ⚠️ Warning: Using force flags (/for-9) can cause data loss or leave the application in an unstable state. Use them only when necessary.
- On Windows, run: