In Ubuntu/Unix we can resolve this problem in 2 steps as described below.
Type netstat -plten |grep java
This will give an output similar to:
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 1001 76084 9488/java
Here 8080
is the port number at which the java process is listening and 9488
is its process id (pid).
In order to free the occupied port, we have to kill this process using the kill
command.
kill -9 9488
9488
is the process id from earlier. We use -9
to force stop the process.
Your port should now be free and you can restart the server.