如何将“不安全"参数传递给 Java Webstart 应用程序的 JVM [英] How to pass 'unsafe' arguments to the JVM of a Java Webstart application

查看:18
本文介绍了如何将“不安全"参数传递给 Java Webstart 应用程序的 JVM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Java Webstart 应用程序在受控的可信环境中运行.这是一个封闭的内部网络,我可以在其中控制应用程序的启动方式.

My Java Webstart application runs in a controlled trusted environment. This is a closed internal network where I have some control on how the application is started.

我如何将 JVM 参数传递给应用程序,即使它们被 JVM 视为不安全"以供 webstart 使用?

How can I pass JVM arguments to the application, even if they are considered 'unsecure' for use by webstart by the JVM?

推荐答案

有几个选项可以将 JVM 参数传递给 webstart.

There are several options to pass JVM arguments to webstart.

  1. 通过 JNLP 文件.
  2. 通过 JAVA_TOOL_OPTIONS 环境变量.
  3. 通过本地计算机上的部署设置.
  4. 通过 javaws 命令(我无法让它工作).

请注意,我已包含指向本文档的 java 8 版本的链接.所有这些想法在其他 Java 版本中都得到支持和记录,但有时它们的工作方式略有不同,或者限制略有变化.

Note that I have included links to the java 8 version of this documentation. All of these ideas are supported and documented in other Java versions, however sometimes they work a tiny bit different, or have slightly changed restrictions.

JNLP 通过 JNLP 文件支持许多 JVM 参数.有些可以通过直接设置完成,例如initial-heap-sizemax-heap-size.对于其他设置,可以使用 java-vm-args.

The JNLP supports many JVM arguments through the JNLP file. Some can be done though direct settings, such as initial-heap-size and max-heap-size. For other settings java-vm-args can be used.

JNLP 文件语法文档列出了此版本"的一些受支持的 java-vm-args,但是不确定这是示例的 1.4+ 版本还是 JRE 8.我知道实际上支持一些未列出的设置,例如作为 -XX:MaxGCPauseMillis 并激活 G1 垃圾收集器.您可以制作 JNLP,然后使用 jinfo -flag MaxGCPauseMillis 来测试设置是否已正确传播.

The JNLP File Syntax documentation lists some supported java-vm-args for 'this version' however it is unsure if that is the version 1.4+ of the example, or JRE 8. I know some unlisted settings are actually supported, such as -XX:MaxGCPauseMillis and activating the G1 garbage collector. You can make a JNLP and then use jinfo -flag MaxGCPauseMillis <pid> to test if a setting has been correctly propagated.

这是首选方法,因为它不需要对 JVM 进行任何直接控制.缺点是仅支持被认为安全"的特定参数.

This is the preferred method, because it does not require any direct control of the JVM. The down-side is that only supports specific parameters that are considered 'safe'.

当您使用 javaws 命令启动 Java Webstart 时,您可以使用 JAVA_TOOL_OPTIONS 在从该环境启动的所有 JVM 上设置您想要的任何参数.

When you start Java Webstart by using the javaws command, you can use the JAVA_TOOL_OPTIONS to set any parameter you want on all JVM started from that environment.

所以在 Linux 中你可以设置一个不受支持的参数:

So in Linux you can do to set an unsupported parameter:

export JAVA_TOOL_OPTIONS=-XX:SoftRefLRUPolicyMSPerMB=2000
javaws <my jnlp>

请注意,这将影响使用此系统变量运行的所有 Java 应用程序.因此,为所有用户或特定用户设置此项时应非常小心.如上例仅针对单个应用程序设置此选项更安全.

Note that this will affect all java applications ran with this system variable. So setting this for all users, or a specific user should be done with great care. Setting this only for a single application as the example above is much safer.

这个解决方案的优点是你可以传递任何你想要的参数.缺点是它需要启动应用程序的特定方式,或非常广泛的设置.它还需要控制客户端系统.

The advantage of this solution is that you can pass any parameter you want. The downside is that it requires a specific way of launching the application, or a very broad setting. It also requires control over the client system.

您还可以通过更改 JVM 的部署设置来传递 JVM 参数.这可以通过 Java 控制面板,它允许您设置默认的运行时设置.

You can also pass JVM arguments by changing the deployment settings of the JVM. This can be done through the Java Control Panel, which allows you to set default runtime settings.

如果您想自动化这些设置,您可以使用 部署属性文件.不幸的是,该文件的 JRE 特定部分没有记录.手动调整此文件非常容易:

If you want to automate these settings you can use the deployment properties file. Unfortunately the JRE specific section of this file is undocumented. Manually it is very easy to adapt this file:

deployment.javaws.jre.0.args=-XX\:SoftRefLRUPolicyMSPerMB\=2000

在自动化此文件时,您必须非常仔细地观察它是否包含所有检测到的 JVM 的这些设置,因此您必须确保更改正确的设置.这也将用于您系统上的所有 Webstart 和小程序.

When automating this file, you have to watch very carefully that it contains these settings for all detected JVMs, so you have to be sure to change the correct one. Also this will be used for all Webstart and applets on your system.

应该有另一种方法(除了JAVA_TOOL_OPTIONS 方法)使用命令行更改参数.javaws 文档 列出了 -J 选项将参数传递给 JVM,例如通过运行 JNLP 如下:

There should be another way (besides the JAVA_TOOL_OPTIONS method) to change the parameters using the command line. The javaws documentation lists the -J option to pass arguments to the JVM, for example by running your JNLP as follows:

javaws -J-XX:SoftRefLRUPolicyMSPerMB=2000 <my jnlp>

然而,我无法得到它来实际设置 JVM 参数.

However I have not been able to get this to actually set the JVM parameters.

这篇关于如何将“不安全"参数传递给 Java Webstart 应用程序的 JVM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆