title: Java Web Start doesn't pass arguments to application when running in browser
body: <p>I'm having trouble passing arguments to a Java application started using Java Web Start. My system is Ubuntu Linux 12.04.1 Precise, but the same also happens in Windows 7. Both use Oracle Java version 1.7.0_09.</p>
  
  <p><strong>Edit</strong>: I'm investigating if a Web Start application would suit our needs better than a normal applet. The problem with an applet is that it gets closed if the user navigates away from the page which is not what we want. (We're also interested in seeing if we can get around a certain security issue by using Web Start instead of an applet.) We'd like to start the application from the browser so that we could pass information about the authenticated user to the Java application. Requiring the user to login in the application seems like a bad solution (we might have to support things like OAuth).</p>
  
  <p>I have a sample program CommandLineArgs.java:</p>
  
  <pre><code>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);
          }
      }
  }
  </code></pre>
  
  <p>I packaged this into a jar:</p>
  
  <pre><code>javac CommandLineArgs.java
  zip cmd.jar CommandLineArgs.class
  </code></pre>
  
  <p>Then I have a JNLP file called cmd.jnlp:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  &lt;!-- Empty codebase means use same directory. --&gt;
  &lt;jnlp spec="1.0+" codebase="https://localhost:9876/"&gt;
      &lt;information&gt;
          &lt;title&gt;Command Line Args Printer&lt;/title&gt;
          &lt;vendor&gt;No one&lt;/vendor&gt;
          &lt;homepage href="https://localhost:9876/"/&gt;
          &lt;description&gt;Application that prints the command line arguments that it gets.&lt;/description&gt;
      &lt;/information&gt;
      &lt;resources&gt;
          &lt;j2se version="1.6+" initial-heap-size="32m" max-heap-size="128m" /&gt;
          &lt;property name="jnlp.versionEnabled" value="true"/&gt;
  
          &lt;jar href="cmd.jar" main="true"/&gt;
  
      &lt;/resources&gt;
      &lt;application-desc main-class="CommandLineArgs"&gt;
          &lt;!-- Here are sample arguments I'd like to pass to the program. --&gt;
          &lt;argument&gt;arg1&lt;/argument&gt;
          &lt;argument&gt;arg2&lt;/argument&gt;
          &lt;argument&gt;arg3&lt;/argument&gt;
      &lt;/application-desc&gt;
  &lt;/jnlp&gt;
  </code></pre>
  
  <p>Here's a HTML page cmd.html I use for testing. The div element was originally created by using deployjava.js: <code>deployJava.launchWebStartApplication('https://localhost:9876/cmd.jnlp')</code></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Java web start command line arguments test&lt;/title&gt;
  
      &lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;div id="div1" style="position: relative; left: -10000px; margin: 0px auto; " class="dynamicDiv"&gt;
      &lt;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/"&gt;
  &lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The fastest way I could get a https server running was to use the openssl tool commonly found in Linuxes. When running the server like this, the current directory should contain cmd.html, cmd.jar and cmd.jnlp .</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Now if I surf to <code>https://localhost:9876/cmd.html</code> I can run the application. The Java console opens and it prints this. Notice that there are 0 command line arguments.</p>
  
  <pre><code>   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:&lt;-Xms32m     satisfy want:&lt;-Xms32m&gt;
  Got 0 command line args:
  </code></pre>
  
  <p>On the other hand, if I run javaws from the command line (<code>javaws cmd.jnlp</code>), I get this in the java console. Now there are 3 command line arguments.</p>
  
  <pre><code>    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:&lt;-Djnlp.versionEnabled=true -Xms32m     satisfy want:&lt;-Xms32m&gt;
  Got 3 command line args:
  arg1
  arg2
  arg3
  </code></pre>
  
  <p>Am I doing something wrong? Why don't the arguments get passed to my program when running in the browser?</p>
  
  <p>I found the post <a href="https://stackoverflow.com/questions/4049994/java-ws-application-ignoring-arguments-sporadically">Java WS application ignoring arguments sporadically</a> that seems to describe the same problem. The solution for posdef was to remove the href attribute from the jnlp element in the jnlp file but I don't have that attribute.</p>