51

My Java browser plug-in is no longer working. When I open a page that has a Java element, Java cannot connect to the server.

After investigation, I found that Java was trying to use IPv6, while my network does not support IPv6, so Java always fails to connect.

I tried looking on Google and found that I should run Java with -Djava.net.preferIPv4Stack=true, but how can I pass this to the browser?

I use Google Chrome and Java 7 update 5.

harrymc
  • 480,290
nyongrand
  • 688

2 Answers2

90

Put the options in _JAVA_OPTIONS environment variable. How to do this is already described in various other posts – although they usually talk about setting PATH, but it's all the same.

For example, on Linux, put the following in your ~/.profile or ~/.bash_profile:

export _JAVA_OPTIONS="-Djava.net.preferIPv4Stack=true"
u1686_grawity
  • 452,512
  • 1
    ok, thanks for your reply, although i use windows but your solution inspire me, thanks – nyongrand Jul 25 '12 at 19:28
  • 1
    See for example this post for setting environment variables: http://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them – user2428118 Aug 30 '13 at 18:12
  • 1
    Why does Java 'prefer' IPV6? It seems to break code that was working. – Ribo Apr 02 '16 at 15:18
  • How to set it in Windows ? – Adnan Ali Jun 18 '17 at 09:51
  • 1
    @Ribo: By default, Java uses dual-stack IPv6 when possible, that is, it uses IPv6 sockets that also support IPv4 addresses. These sockets are still compatible with IPv4 applications by using IPv4-mapped addresses. Therefore, this is a backward-compatible behavior. – Dr. Koutheir Attouchi Aug 24 '17 at 08:38
  • IPv4-mapped addresses break proxies. – MarcH Dec 05 '18 at 00:44
0

when launching from the command line, add parameter:

-Djava.net.preferIPv4Stack=true

ie:

java -jar -Djava.net.preferIPv4Stack=true some.jar

alex
  • 1
  • The environment variable mentioned in the other answer will also work, though, and is recommended over environments where the java cmd isn't directly accessible – OneCricketeer Sep 06 '23 at 18:49