50

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
  • 455,459
  • 31
  • 526
  • 924
nyongrand
  • 676
  • 1
  • 6
  • 11
  • Why don't you disable the IPv6 protocol so Java won't have this option. – harrymc Aug 30 '13 at 18:55
  • it is a old story, I do not know if I've disable IPv6 protocol, seems to have, I've forgotten, what I remember is I remove Java 7 and replace it with Java 6 – nyongrand Aug 31 '13 at 09:21
  • 1
    Disabling is easy : [see this](http://www.informationweek.com/byte/personal-tech/desktop-operating-systems/how-to-disable-ipv6-on-windows-7/231400022). – harrymc Aug 31 '13 at 09:25
  • @harrymc always copy content: that link is dead. – WestCoastProjects Jan 16 '17 at 03:12
  • 1
    @javadba: Links are never dead : [see the Wayback Machine](https://web.archive.org/web/20130916222122/http://www.informationweek.com/byte/personal-tech/desktop-operating-systems/how-to-disable-ipv6-on-windows-7/231400022), but it's outdated. Better google "Disable IPv6 On Windows" for half a million results. – harrymc Jan 16 '17 at 07:31
  • @harrymc Got 6.8 million results today :) – Jason S Sep 30 '21 at 04:51

2 Answers2

89

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
  • 426,297
  • 64
  • 894
  • 966
  • 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