java - Check programatically (without string-matching) whether using IPV6 or IPV4 for JVM -
i want check whether jvm options particular application (in case, matlab) have been set prefer ipv4 or if still use ipv6.
i know how set jvm prefer ipv4. in case, can done adding line
-djava.net.preferipv4stack=true
to java.opts file within $matlabroot/bin/maci64/.
i can check whether line has been added java.opts via string-matching. i've pasted current solution (a matlab script checks string-match, , adds line if not exist) @ bottom of question.
i don't know how, though, check whether ipv4 or ipv6 preferred without string-matching. seems preferred.
does know how check ipv4 vs. ipv6 in jvm without string-matching?
here's current solution, depends on string-matching:
% osx platform-specific: revert ipv4 if (computer('arch') == 'maci64') javaoptspath = fileread([matlabroot '/bin/' computer('arch') '/java.opts']); k = strfind(javaoptspath, '-djava.net.preferipv4stack=true'); if isempty(k) setenv('drake_ipv4_set_matlabroot', matlabroot) setenv('drake_ipv4_set_arch', computer('arch')) display('since on mac, need set jvm prefer ipv4 instead of ipv6 matlab') display('please enter sudo password below') ! (echo "" | echo "-djava.net.preferipv4stack=true") | sudo tee -a $drake_ipv4_set_matlabroot/bin/$drake_ipv4_set_arch/java.opts end end
you can access underlying java system properties without parsing options string using java.lang.system
class directly matlab.
for example:
ipv4_preferred = java.lang.system.getproperty('java.net.preferipv4stack')
the result of getproperty empty if user has not set -djava.net.preferipv4stack=...
, more complete solution might be:
ipv4_preferred = java.lang.system.getproperty('java.net.preferipv4stack'); if isempty(ipv4_preferred) ipv4_preferred = false; end
Comments
Post a Comment