Preparing for Java and Spring Boot Interview?

Join my Newsletter, its FREE

Thursday, September 28, 2023

Fixing Cannot assign requested address: JVM_Bind in Tomcat, Jetty

One of the most dreaded errors in Java-based client server-based applications is a networking-related error, e.g. Cannot assign requested address: JVM_Bind. I have faced this issue while working with web servers like Tomcat, Jetty, and Weblogic before, but yesterday it came again when one of my colleagues faced this issue in Windows. As soon as Java programmers see, they come to the conclusion that it's an issue with two processes listening on the same port and often mistook it for Address already in use: JVM_Bind:8080, which is slightly different than this.

If you look at Java documentation for, you will find this "Signals that an error occurred while attempting to bind a socket to a local address and port. Typically, the port is in use, or the requested local address could not be assigned."

It's the second part, which is more interesting in the case of Cannot assign requested address: JVM_Bind.

When you start a web server or application server, which typically listens on a port e.g. Tomcat or Jetty listens on 8080 and 8084 for HTTP and HTTPS traffic, they bind a socket to a local address and port. 

If you give them hostnames like localhost or devhost, then they used /etc/host in both Windows and Linux to resolve the domain name into IP address, if this mapping is incorrect then you will get Cannot assign requested address: JVM_Bind.

This host to IP address mapping file can be found at C:\Windows\System32\Drivers\etc\hosts, where C:\Windows is where you have installed Windows operating system. If you look at this file, you will see it contains IP address and hostname as shown below:

# localhost localhost

If this mapping is changed and localhost cannot be resolve to then you will get Cannot assign requested address: JVM_Bind. You can try by following program to reproduce this issue, remember, you need admin rights to change /etc/host settings in Windows.
How to fix Cannot assign requested address: JVM_Bind in Tomcat, Jetty


public class ServerSocketTesting {

    public static void main(String args[]) throws IOException {

        ServerSocket server = new ServerSocket(8080);
        System.out.println("Server is started, listening connections on port :8080 ");

If your /etc/host mapping is incorrect then you will see something like

Exception in thread "main" 
Cannot assign requested address: JVM_Bind
    at Method)

Just, correct the mapping, or add against the localhost to resolve this issue.  That's all about how to fix Cannot assign requested address: JVM_Bind error in Java-based client-server application like Minecraft, a popular game in Java, which also communicates with the server and other machines using TCP and sockets.

 It could also occur when you are using web and application servers like Tomcat, Jetty, or Weblogic as well.

Next time, instead of thinking that two processes are listening on the same port, also think about hostname to IP address resolution issue and verify contents of /etc/host file in both Windows and Linux. 

Let me know if you are facing this issue and not able to resolve it, pasting the error message and what you are trying to do will help to solve your error quickly and accurately.

How to resolve Cannot assign requested address: JVM_Bind in Tomcat

If you are getting this issue in the Tomcat web server then open your server.xml, which contains host and port information for Tomcat connectors. You can find server.xml in location (Windows OS) C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.41\conf\server.xml

Now look for your connector, if you are using default settings then your connector will look like this :

 <Connector port="8080" protocol="HTTP/1.1"
               redirectPort="8443" />

but if you have modified it to include address="TestServer", then look for TestServer mapping in the/etc/hosts file. Try ping with the IP address and see if it is up or not, you will find that it's incorrect. Just update with the right IP and restart Tomcat.

Similarly, you can resolve Cannot assign requested address: JVM_Bind in Jetty or any other web server. The key thing is not to confuse this error with an address already in use error.

Other Java Error and Exception tutorials you may like to read
  • How to solve java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Java MySQL
  • Spring Boot Error - Error creating a bean with name 'dataSource' defined in class path resource DataSourceAutoConfiguration 
  • How to fix @Autowired - No qualifying bean of type found for dependency in Spring Boot? 
  • How to fix java.lang.ClassNotFoundException: org.postgresql.Driver error in Java? [solution]
  • How to fix java.lang.ClassNotFoundException: Error in Java? [solution]
  • java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory? [solution]
  • How to solve java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver in Java? [solution]
  • How to connect Oracle database from Java Program? (example)
  • How to solve java.lang.unsatisfiedlinkerror no ocijdbc11 in java.library.path? (solution)

  • All the best and let me know if you face similar issues.


    Anonymous said...

    Hello there I am getting below exception, while running QuickFIXJ based FIX engine :

    Caused by: Cannot assign requested address
    at Method)
    at org.apache.mina.transport.socket.nio.SocketAcceptor.registerNew(
    at org.apache.mina.transport.socket.nio.SocketAcceptor.access$800(
    at org.apache.mina.transport.socket.nio.SocketAcceptor$

    It runs fine on my desktop but as soon as I try to run it on Linux, it gives me this exception, I have already check no other instance of program is running and no other process is using this port.

    SARAL SAXENA said...

    @Anonymous ..Most likely related to another process using port . On Windows, run the command:

    netstat -a -n | find "LIST"

    And it should list anything there that's hogging the port. Of course you'll then have to go and manually kill those programs in Task Manager. If this still doesn't work, replace the line:

    serverSocket = new ServerSocket(9999);


    InetAddress locIP = InetAddress.getByName("");
    serverSocket = new ServerSocket(9999, 0, locIP);

    Of course replace with your actual IP address, or use

    Pascal said... could also help (if worked for me adding this to my tomcat settings)

    Unknown said...

    Verify ipaddress in /etc/init.d/jbossas if Jboss is configured as a service.

    Anonymous said...


    Unknown said...

    PLS help me im 12, but i know a lot about coding and want to host a minecrt server.... However this error keeps popping up when i try to run it :(
    [12:45:57] [Server thread/INFO]: Using default channel type
    [12:45:59] [Server thread/WARN]: **** FAILED TO BIND TO PORT!
    [12:45:59] [Server thread/WARN]: The exception was: Cannot assign requested address: bind
    [12:45:59] [Server thread/WARN]: Perhaps a server is already running on that port?

    i went to C:\Windows\System32\drivers\etc\hosts also and it just says

    # Copyright (c) 1993-2009 Microsoft Corp.
    # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
    # This file contains the mappings of IP addresses to host names. Each
    # entry should be kept on an individual line. The IP address should
    # be placed in the first column followed by the corresponding host name.
    # The IP address and the host name should be separated by at least one
    # space.
    # Additionally, comments (such as these) may be inserted on individual
    # lines or following the machine name denoted by a '#' symbol.
    # For example:
    # # source server
    # # x client host

    # localhost name resolution is handled within DNS itself.
    # localhost
    # ::1 localhost

    please read carefully and help me play minecraft with my friends

    javin paul said...

    Hello there, which port you are trying to run your server? use a port which is greater than 999, also check if another process, previous instance of same is running on that port. The error indicates invalid port or an already running instance.

    Post a Comment