问题
I need to set java.net.preferIPv4Stack=true to an app started via JNLP (javaws and applet)
Tried those, without luck...
<j2se ...java-vm-args="-Djava.net.preferIPv4Stack=true" />
<property name="java.net.preferIPv4Stack" value="true"/>
System.setProperty("java.net.preferIPv4Stack", "true");
The only way i could make it work was seeting when launching javaws from local filesystem:
javaws -J-Djava.net.preferIPv4Stack=true myapp.jnlp
What is not possible on a applet or URL.
How should i set this property?
回答1:
With the Java 7 Update 6 (b17) the list of secure properties has been updated. See Bug Report 716069 for further Details.
You can include this setting by specifying the following line within the resource tag:
<property name="java.net.preferIPv4Stack" value="true"/>
回答2:
The only properties that you can set in the JNLP are those considered secure which do not include java.net.preferIPv4Stack
.
The alternative options you have are (not tested):
- pass the parameter directly to javaws like you did:
javaws -J-Djava.net.preferIPv4Stack=true myapp.jnlp
- Java Control Panel > Java > View > Runtime Parameters, but that is a global setting for all webstart applications and applets using the version of the JRE for which you changed the setting
- use an environment variable:
JAVAWS_VM_ARGS = -Djava.net.preferIPv4Stack=true
- flag the setting as secure by adding a line to the deployment.properties file, located in the Deployment Home(*) :
deployment.javaws.secure.properties=java.net.preferIPv4Stack
- note: not sure if this is available Java > 1.5.
The first 3 options are detailed in this document.
(*) Deployment Home:
Windows XP: %HOME%\Application Data\Sun\Java\Deployment
Windows 7/Vista: %APPDATA%\..\LocalLow\Sun\Java\Deployment
Linux/Solaris: %HOME%/.java/deployment
回答3:
Also, for future readers - environment variable for applets:
_JPI_VM_OPTIONS
e.g.
_JPI_VM_OPTIONS=-Djava.net.preferIPv4Stack=true
来源:https://stackoverflow.com/questions/9809919/how-to-set-preferipv4stack-property-for-jnlp-app