And*_*ndy 5 java security jnlp templates wildcard
自Java 7u40中的最后一次安全性更改以来,需要对JNLP文件进行签名.这可以通过在JNLP-INF/APPLICATION.JNLP中添加最终JNLP ,或通过在签名主jar 中的JNLP-INF/APPLICATION_TEMPLATE.JNLP中提供模板JNLP来完成.
第一种方法效果很好,但我们希望允许将以前未知数量的运行时参数传递给我们的应用程序.
因此,我们的APPLICATION_TEMPLATE.JNLP如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<jnlp codebase="*">
<information>
<title>...</title>
<vendor>...</vendor>
<description>...</description>
<offline-allowed />
</information>
<security>
<all-permissions/>
</security>
<resources>
<java version="1.7+" href="http://java.sun.com/products/autodl/j2se" />
<jar href="launcher/launcher.jar" main="true"/>
<property name="jnlp...." value="*" />
<property name="jnlp..." value="*" />
</resources>
<application-desc main-class="...">
*
</application-desc>
</jnlp>
Run Code Online (Sandbox Code Playgroud)
问题是application-desc标签内部的*.
可以使用多个参数标记对固定数量的参数进行通配符(参见下面的代码),但是不可能为应用程序提供更多或更少的参数(Java Webstart不会以空参数标记开头).
<application-desc main-class="...">
<argument>*</argument>
<argument>*</argument>
<argument>*</argument>
</application-desc>
Run Code Online (Sandbox Code Playgroud)
有人可以确认此问题和/或是否有将先前未定义的运行时参数传递给Java应用程序的解决方案?
非常感谢!
从我在阅读JNLP 7规范后看到的内容看来,你想要的就是你无法做到的.星号只能表示文本数据,而不能表示多个XML元素.
在您的情况下,我将使该main方法能够自己解析单个参数,以便可以使用自定义分隔符将其视为多个值.像这样的东西:
public static void main(String[] args) {
if (args.length == 2 && args[0].equals("--args")) {
args = args[1].split(";;");
}
// Continue as normal
}
Run Code Online (Sandbox Code Playgroud)
这允许模板包含:
<application-desc main-class="com.example.app.Main">
<argument>--args</argument>
<argument>*</argument>
</application-desc>
Run Code Online (Sandbox Code Playgroud)
而你的实际.jnlp文件可能包含以下内容:
<application-desc main-class="com.example.app.Main">
<argument>--args</argument>
<argument>files.txt;;29;;true;;1384212567908</argument>
</application-desc>
Run Code Online (Sandbox Code Playgroud)