# 设置受信任的参数和安全属性

> 原文： [https://docs.oracle.com/javase/tutorial/deployment/doingMoreWithRIA/settingArgsProperties.html](https://docs.oracle.com/javase/tutorial/deployment/doingMoreWithRIA/settingArgsProperties.html)

您可以在 RIA 的 Java 网络启动协议（JNLP）文件中为富 Internet 应用程序（RIA）设置某些 Java 虚拟机参数和安全属性。对于 applet，您还可以在`&lt;applet&gt;`标签的`java_arguments`参数中设置参数。虽然有一组预定义的安全属性，但您也可以通过在属性名称前加上“`jnlp.`”或“`javaws.`”来定义新的安全属性。可以使用`System.getProperty`方法在 RIA 中检索属性。

考虑 Properties 和 Arguments Demo applet。以下 Java 虚拟机参数和属性在 applet 的 JNLP 文件 [`appletpropsargs.jnlp`](examples/applet_PropertiesAndVMArgs/src/appletpropsargs.jnlp) 中设置。

*   `-Xmx` - 安全参数设置等于“256M”
*   `sun.java2d.noddraw` - 预定义的安全属性设置等于“true”
*   `jnlp.myProperty` - 用户定义的安全属性集，等于“用户定义的属性”

```
<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="" href="">
    <information>
        <title>Properties and Arguments Demo Applet</title>
        <vendor>Dynamic Team</vendor>
    </information>
    <resources>
        <!-- Application Resources -->
        <j2se version="1.6+"
              href="http://java.sun.com/products/autodl/j2se"
              <!-- secure java vm argument -->
              java-vm-args="-Xmx256M"/>
        <jar href="applet_PropertiesAndVMArgs.jar"
            main="true" />
            <!-- secure properties -->
        <property name="sun.java2d.noddraw"
            value="true"/>
        <property name="jnlp.myProperty"
            value="a user-defined property"/>
    </resources>
    <applet-desc 
         name="Properties and Arguments Demo Applet"
         main-class="PropertiesArgsDemoApplet"
         width="800"
         height="50">             
     </applet-desc>
     <update check="background"/>
</jnlp>

```

[`PropertiesArgsDemoApplet`](examples/applet_PropertiesAndVMArgs/src/PropertiesArgsDemoApplet.java) 类使用`System.getProperty`方法检索`java.version`属性以及在 JNLP 文件中设置的其他属性。 `PropertiesArgsDemoApplet`类也显示属性。

```
import javax.swing.JApplet;
import javax.swing.SwingUtilities;
import javax.swing.JLabel;

public class PropertiesArgsDemoApplet extends JApplet {
    public void init() {
        final String javaVersion = System.getProperty("java.version");
        final String  swing2dNoDrawProperty = System.getProperty("sun.java2d.noddraw");
        final String  jnlpMyProperty = System.getProperty("jnlp.myProperty");        

        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    createGUI(javaVersion, swing2dNoDrawProperty, jnlpMyProperty);
                }
            });
        } catch (Exception e) {
            System.err.println("createGUI didn't successfully complete");
        }
    }
    private void createGUI(String javaVersion, String swing2dNoDrawProperty, String jnlpMyProperty) {
        String text = "Properties: java.version = " + javaVersion + 
                ",  sun.java2d.noddraw = " + swing2dNoDrawProperty +
                ",   jnlp.myProperty = " + jnlpMyProperty;
        JLabel lbl = new JLabel(text);
        add(lbl);
    }
}

```

接下来显示 Properties 和 Arguments Demo applet。您还可以在 [`AppletPage.html`](examples/dist/applet_PropertiesAndVMArgs/AppletPage.html) 中看到运行的小程序。

<noscript>A browser with JavaScript enabled is required for this page to operate properly.</noscript>

* * *

**Note:**  If you don't see the applet running, you need to install at least the [Java SE Development Kit (JDK) 6 update 10](http://www.oracle.com/technetwork/java/javase/downloads/index.html) release.

* * *

* * *

**Note:**  If you don't see the example running, you might need to enable the JavaScript interpreter in your browser so that the Deployment Toolkit script can function properly.

* * *

[下载 _ 属性和参数演示 Applet_ 示例的源代码](examplesIndex.html#PropertiesAndVMArgs)以进一步进行实验。

有关 RIA 可以访问的一整套系统属性，请参见[系统属性](properties.html)。