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

查看:63
本文介绍了如何将“不安全"参数传递给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参数被Webstart认为是不安全的",我如何将JVM参数传递给应用程序?

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+还是JRE8.我知道实际上支持某些未列出的设置,例如-XX:MaxGCPauseMillis和激活G1垃圾收集器.您可以制作一个JNLP,然后使用jinfo -flag MaxGCPauseMillis <pid>来测试设置是否已正确传播.

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和applet.

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天全站免登陆