Reputation: 83
I have searched many places of making IPv6 enabled to have a dual-stack machine IPv6. I found many have answered to set java.net.preferIPv6Addresses=true which is set to false by default.
I want to know where exactly should I make these changes, i.e in which file or do I have to write some Java code to put this into.
Upvotes: 8
Views: 14238
Reputation: 719376
The setting needs to get into the JVM's system properties ... and it needs to be there before the relevant part of the Java class library initializes.
The "bomb proof" way to do this is to pass the setting to the JVM as a command line parameter; e.g.
java -Djava.net.preferIPv6Addresses=true ... com.example.MainClass <args>
You could also code your application to inject the setting using
System.setProperty("java.net.preferIPv6Addresses", "true");
but you need to ensure that the injection happens soon enough1, and that would not be trivial.
1 - "Soon enough" means before JVM networking code's static initialization has occurred. This can be difficult to achieve in a complex application. Note the the Network Properties documentation states: "Some are checked only once at startup of the VM, and therefore are best set using the -D option of the java command ...". Note that it does NOT state that those properties can only be set that way.
The suggestion of using a JAVA_OPTS
environment variable will only work for some applications. The handling of JAVA_OPTS
will happen in your application's launcher or wrapper script before the JVM is launched. The same applies to _JAVA_OPTIONS
... which is one that I've not seen before.
(If the application you are using is properly documented, then its documentation should explain how to specify options that need to be passed to the java.exe
launcher.)
The standard java.exe
and javaw.exe
commands certainly DO NOT pay any attention to the JAVA_OPTS
environment variable.
Upvotes: 12
Reputation: 1561
you must put in in your enviorment path before running the java executable. in linux
export JAVA_OPTS="-Djava.net.preferIPv4Stack=true" (same for ipv6 )
Upvotes: 0