title: How to run the Java applications, from Google chrome app?
body: <p>How to run Java using Google chrome app extension? Following .exe works but when i use .jar its failing.</p>
  
  <p>What is am i doing wrong?</p>
  
  <p>C# works:</p>
  
  <pre><code>{
    "name": "com.google.chrome.example.echo",
    "description": "Chrome Native Messaging API Example Host",
    "path": "C:\\Users\\Documents\\Visual Studio 2013\\Projects\\ConsoleApplication1\\ConsoleApplication1\\bin\\Debug\\ConsoleApplication1.exe",
    "type": "stdio",
    "allowed_origins": [
      "chrome-extension://knldjmfmopnpolahpmmgbagdohdnhkik/"  
    ]
  }
  </code></pre>
  
  <p>C# code:</p>
  
  <pre><code>using System.Text;
  using System.Threading.Tasks;
  using System.IO;
  
  namespace ConsoleApplication1 {
      class Program {
          public static void Main(string[] args) {
              string message = "test message from native app.";
              OpenStandardStreamOut(message);
          }
  
          private static void OpenStandardStreamOut(string stringData)
          {
              // We need to send the 4 btyes of length information
              string msgdata = "{\"text\":\"" + stringData + "\"}";
  
              int DataLength = msgdata.Length;
              Stream stdout = Console.OpenStandardOutput();
              stdout.WriteByte( (byte) (DataLength &gt;&gt; 0)  );
              stdout.WriteByte( (byte) (DataLength &gt;&gt; 8)  );
              stdout.WriteByte( (byte) (DataLength &gt;&gt; 16) );
              stdout.WriteByte( (byte) (DataLength &gt;&gt; 24) );
  
              // Available total length : 4,294,967,295 ( FF FF FF FF )
              Console.Write(msgdata);
          }
  
  
      }
  }
  </code></pre>
  
  <p><strong>Java Fails:</strong></p>
  
  <pre><code>{
    "name": "com.google.chrome.example.echo",
    "description": "Chrome Native Messaging API Example Host",
    "path": "java -cp C:\\Users\\\Downloads\\eid.jar eid.Eid",
    "type": "stdio",
    "allowed_origins": [
      "chrome-extension://knldjmfmopnpolahpmmgbagdohdnhkik/"  
    ]
  }
  </code></pre>
  
  <p>Java:</p>
  
  <pre><code>// test packet exchange form java to google chrome live/real-time
  import java.io.ByteArrayOutputStream;
  import java.io.IOException;
  
  public class Eid {
      public static void main(String[] args) throws Exception {
        String str = "";
        byte[] bs = {65, 66, 67, 68, 69};
        ByteArrayOutputStream baos = null;
  
        try{
  
           // create new ByteArrayOutputStream
           baos = new ByteArrayOutputStream();
  
           // write byte array to the output stream
           baos.write(bs);
  
           // converts buffers content using Cp1047 character set
           str = baos.toString("Cp1047");
           System.out.println(str);
  
           // converts buffers contents using UTF-8 character set
           str = baos.toString("UTF-8");
           System.out.println(str);
  
        }catch(Exception e){
  
           // if I/O error occurs
           e.printStackTrace();
        }finally{
           if(baos!=null)
              baos.close();
        }  
      }
  }
  </code></pre>
  
  <p>EDIT: failing too.</p>
  
  <pre><code>package eid;
  import java.io.ByteArrayOutputStream;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.PrintStream;
  
  public class Eid {
    public static final byte[] intToByteArray(int value) {
        return new byte[] {
                (byte)(value &gt;&gt;&gt; 24),
                (byte)(value &gt;&gt;&gt; 16),
                (byte)(value &gt;&gt;&gt; 8),
                (byte)value};
    }  
  
    public static void main(String[] args) throws Exception {
      PrintStream original = new PrintStream(System.out);
      System.setOut(new PrintStream(new FileOutputStream("NUL:")));
      System.out.println("bar");  // no output
      original.println("foo");    // output to stdout
    }
  }
  </code></pre>