Tomcat Cannot assign requested address: JVM_Bind non port occupation conflict

  • 2020-05-30 20:16:44
  • OfStack

Preface:

Recently, when installing and starting Tomcat 6.0, my friend found that 1 could not start correctly. The main exception stack information is as follows:


 serious : StandardServer.await: create[8005]: 
java.net.BindException: Cannot assign requested address: JVM_Bind
 at java.net.PlainSocketImpl.socketBind(Native Method)
 at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:359)
 at java.net.ServerSocket.bind(ServerSocket.java:319)
 at java.net.ServerSocket.(ServerSocket.java:185)
 at org.apache.catalina.core.StandardServer.await(StandardServer.java:406)
 at org.apache.catalina.startup.Catalina.await(Catalina.java:676)
 at org.apache.catalina.startup.Catalina.start(Catalina.java:628)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
 at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

Friends' Tomcat 6.0 is the official install-free version and has just been downloaded, so it should not be a problem of missing files.

Based on the exception information, it could be that the port or some resource that Tomcat needs to bind to is occupied by another application.

Use the DOS command netstat-an to view the occupied port. No program has been found to be using the port used by Tomcat (for example, 8080). Change the port in the conf/ server.xml file in the Tomcat installation directory to another port.

Through a variety of tests, it can be preliminarily determined that the problem should not be caused by port occupation. If it's not port occupancy, consider whether it's an IP binding.

After checking, the following contents were found in the C:\Windows\System32\drivers\etc\hosts file on the friend's server computer:


127.0.0.1    localhost
169.196.254.14  localhost

169.196.254.14 is a local IP address that does not exist. After removing the content of the second line 169.196.254.14 localhost in the hosts file, start Tomcat again.

In the server world, it is common for one computer to have multiple IP addresses. When Tomcat is started, it will get all the IP addresses according to the configuration and bind them one by one. When it is found that the IP addresses that need to be bound do not exist, the above exception will be triggered, resulting in the failure to start normally.


// The output localhost All of the mapped IP address 
InetAddress[] ips = InetAddress.getAllByName("localhost");
if (ips != null) {
  for (InetAddress ip : ips) {
    System.out.println(ip.getHostAddress());
  }
}
/*  Modify the above hosts Before the file, output: 
* 169.196.254.14
* 127.0.0.1
*  After modifying the file, output 
* 127.0.0.1
*/

Thank you for reading, I hope to help you, thank you for your support of this site!


Related articles: