how to force a java jvm to listen on ipv4 instead of ipv6

nowadays, when launching a java app that creates a listening socket, it often defaults to listening to ipv6 exclusively. that would be great, but many current OS’s include a lot of code that only _ sort of _ support ipv6. for instance, notice the * + 127.0.0.1 +* address in the following output from netstat on a linux box:

# netstat -pant | grep 8080
tcp6   0   0 127.0.0.1:8080     :::*     LISTEN      24737/java

sigh…

sometimes it’s quickest to simply force ipv4. if one has access to the code being run, add:

+ System.setProperty("java.net.preferIPv4Stack", "true"); +

if not, when launching from the command line, try adding this parameter:

+ -Djava.net.preferIPv4Stack=true +