JavaWebStartを使用して開始したJavaアプリケーションに引数を渡すのに問題があります。私のシステムはUbuntuLinux12.04.1 Preciseですが、Windows7でも同じことが起こります。どちらもOracleJavaバージョン1.7.0_09を使用しています。
編集:私は、WebStartアプリケーションが通常のアプレットよりも私たちのニーズに適しているかどうかを調査しています。アプレットの問題は、ユーザーがページから移動すると閉じられることです。これは、私たちが望んでいることではありません。(アプレットの代わりにWeb Startを使用して、特定のセキュリティ問題を回避できるかどうかにも関心があります。)認証されたユーザーに関する情報をに渡すことができるように、ブラウザーからアプリケーションを起動したいと思います。 Javaアプリケーション。ユーザーにアプリケーションへのログインを要求することは悪い解決策のようです(OAuthなどをサポートする必要があるかもしれません)。
私はサンプルプログラムCommandLineArgs.javaを持っています:
public class CommandLineArgs {
public static void main(String[] args) {
System.out.println(String.format("Got %d command line args:", args.length));
for (String arg : args) {
System.out.println(arg);
}
}
}
私はこれを瓶に詰めました:
javac CommandLineArgs.java
zip cmd.jar CommandLineArgs.class
次に、cmd.jnlpというJNLPファイルがあります。
<?xml version="1.0" encoding="utf-8"?>
<!-- Empty codebase means use same directory. -->
<jnlp spec="1.0+" codebase="https://localhost:9876/">
<information>
<title>Command Line Args Printer</title>
<vendor>No one</vendor>
<homepage href="https://localhost:9876/"/>
<description>Application that prints the command line arguments that it gets.</description>
</information>
<resources>
<j2se version="1.6+" initial-heap-size="32m" max-heap-size="128m" />
<property name="jnlp.versionEnabled" value="true"/>
<jar href="cmd.jar" main="true"/>
</resources>
<application-desc main-class="CommandLineArgs">
<!-- Here are sample arguments I'd like to pass to the program. -->
<argument>arg1</argument>
<argument>arg2</argument>
<argument>arg3</argument>
</application-desc>
</jnlp>
これが私がテストに使用するHTMLページcmd.htmlです。div要素は元々deployjava.jsを使用して作成されました。deployJava.launchWebStartApplication('https://localhost:9876/cmd.jnlp')
<!DOCTYPE html>
<html>
<head>
<title>Java web start command line arguments test</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<div id="div1" style="position: relative; left: -10000px; margin: 0px auto; " class="dynamicDiv">
<embed type="application/x-java-applet;jpi-version=1.7.0_09" width="0" height="0" launchjnlp="https://localhost:9876/cmd.jnlp" docbase="https://localhost:9876/">
</div>
</body>
</html>
httpsサーバーを実行するための最速の方法は、Linuxで一般的に見られるopensslツールを使用することでした。このようにサーバーを実行する場合、現在のディレクトリにはcmd.html、cmd.jar、およびcmd.jnlpが含まれている必要があります。
sudo cp /etc/ssl/private/ssl-cert-snakeoil.key .
sudo chmod 666 ssl-cert-snakeoil.key
openssl req -batch -new -x509 -key ssl-cert-snakeoil.key -out ssl-cert-snakeoil.key.crt
openssl s_server -cert ssl-cert-snakeoil.key.crt -key ssl-cert-snakeoil.key -accept 9876 -WWW
これで、ネットサーフィンすればhttps://localhost:9876/cmd.html
アプリケーションを実行できます。Javaコンソールが開き、これが出力されます。コマンドライン引数が0であることに注意してください。
JNLP Ref (absolute): https://localhost:9876/cmd.jnlp
Match: beginTraversal
Match: digest selected JREDesc: JREDesc[version 1.6+, heap=33554432-134217728, args=null, href=null, sel=false, null, null], JREInfo: JREInfo for index 0:
platform is: 1.7
product is: 1.7.0_09
location is: http://java.sun.com/products/autodl/j2se
path is: /opt/jre1.7.0_09/bin/java
args is: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8001
native platform is: Linux, amd64 [ x86_64, 64bit ]
JavaFX runtime is: JavaFX 2.2.3 found at /opt/jre1.7.0_09/
enabled is: true
registered is: true
system is: true
Match: ignoring maxHeap: 134217728
Match: selecting InitHeap: 33554432
Match: digesting vmargs: null
Match: digested vmargs: [JVMParameters: isSecure: true, args: ]
Match: JVM args after accumulation: [JVMParameters: isSecure: true, args: ]
Match: digest LaunchDesc: null
Match: digest properties: []
Match: JVM args: [JVMParameters: isSecure: true, args: ]
Match: endTraversal ..
Match: JVM args final: -Xms32m
Match: Running JREInfo Version match: 1.7.0.09 == 1.7.0.09
Match: Running JVM args match: have:<-Xms32m satisfy want:<-Xms32m>
Got 0 command line args:
一方、コマンドライン(javaws cmd.jnlp
)からjavawsを実行すると、これはjavaコンソールで取得されます。現在、3つのコマンドライン引数があります。
Match: beginTraversal
Match: digest selected JREDesc: JREDesc[version 1.6+, heap=33554432-134217728, args=null, href=null, sel=false, null, null], JREInfo: JREInfo for index 0:
platform is: 1.7
product is: 1.7.0_09
location is: http://java.sun.com/products/autodl/j2se
path is: /opt/jre1.7.0_09/bin/java
args is: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8001
native platform is: Linux, amd64 [ x86_64, 64bit ]
JavaFX runtime is: JavaFX 2.2.3 found at /opt/jre1.7.0_09/
enabled is: true
registered is: true
system is: true
Match: ignoring maxHeap: 134217728
Match: selecting InitHeap: 33554432
Match: digesting vmargs: null
Match: digested vmargs: [JVMParameters: isSecure: true, args: ]
Match: JVM args after accumulation: [JVMParameters: isSecure: true, args: ]
Match: digest LaunchDesc: null
Match: digest properties: []
Match: JVM args: [JVMParameters: isSecure: true, args: ]
Match: endTraversal ..
Match: JVM args final: -Xms32m
Match: Running JREInfo Version match: 1.7.0.09 == 1.7.0.09
Match: Running JVM args match: have:<-Djnlp.versionEnabled=true -Xms32m satisfy want:<-Xms32m>
Got 3 command line args:
arg1
arg2
arg3
私は何か間違ったことをしていますか?ブラウザで実行しているときに、引数がプログラムに渡されないのはなぜですか?
同じ問題を説明しているように見える引数を散発的に無視するポストJavaWSアプリケーションを見つけました。posdefの解決策は、jnlpファイルのjnlp要素からhref属性を削除することでしたが、私にはその属性がありません。