title: How can i use applet send data to serial port via rxtxComm.jar On ubuntu
body: <p>I write a program use applet to access serial port via rxtxComm.jar,i change the java.policy,so the applet can access serial port without signed.When the program running on 
  Windows,it's effective.But on ubuntu there have some execptions(<strong>java.lang.reflect.InvocationTargetException and "error calling method on npobject"</strong> ).In order to solve this problem,i have spent many times to google,i couldn't solve.Is anyone have the same problem? Here is the code about this program.</p>
  
  <p><strong>print.html</strong>:</p>
  
  <pre><code>function print() {
      var zplText = $("#zplText").val();
      document.printApplet.print(zplText);
  }
  
  
  
  &lt;textarea rows="5" cols="6" id="zplText"&gt;&lt;/textarea&gt;
  &lt;a href="#" onClick="print()"&gt;print&lt;/a&gt;
  &lt;applet id="printApplet" alt="" codebase=.. code="zpl/ZplPrint.class"&gt;
      &lt;PARAM NAME="archive" VALUE="../lib/RXTXcomm.jar"&gt;
  &lt;/applet&gt;
  </code></pre>
  
  <p><strong>ZplPrint.java</strong>:</p>
  
  <pre><code>public class ZplPrint extends Applet {
  static String zpl;
  static CommPortIdentifier portId;
  static CommPort commPort;
  static SerialPort serialPort;
  @SuppressWarnings("rawtypes")
  static Enumeration portList;
  static OutputStream out;
  
  public void print(String zplText) {
      zpl = zplText;
      if (zpl == null) {
          return;
      }
      byte[] zplByte = zpl.getBytes();
  
      portList = CommPortIdentifier.getPortIdentifiers();
      while (portList.hasMoreElements()) {
          portId = (CommPortIdentifier) portList.nextElement();
          if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
  
              try {
  
                  commPort = portId.open(portId.getName(), 2000);
                  serialPort = (SerialPort) commPort;
  
                  serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
                          SerialPort.PARITY_NONE);
                  out = serialPort.getOutputStream();
                  out.write(zplByte);
                  commPort.close();
              } catch (PortInUseException e) {
                  e.printStackTrace();
              } catch (UnsupportedCommOperationException e) {
                  e.printStackTrace();
              } catch (IOException e) {
                  e.printStackTrace();
              } catch (NullPointerException e) {
                  e.printStackTrace();
              }
  
              System.out.println("Find CommPort: " + portId.getName());
          }
      }
  
  }
  </code></pre>
  
  <p><strong>java.policy</strong>:</p>
  
  <ul>
  <li>permission java.lang.RuntimePermission "loadLibrary.rxtxSerial";</li>
  <li>permission java.io.FilePermission "${java.home}${/}lib${/}ext${/}x86${/}rxtxSerial.dll", "read";</li>
  <li>permission java.util.PropertyPermission "gnu.io.log.mode", "read";</li>
  <li>permission java.util.PropertyPermission "gnu.io.SerialPorts", "write,read";</li>
  <li>permission java.util.PropertyPermission "gnu.io.rxtx.SerialPorts", "read,write";</li>
  <li>permission java.util.PropertyPermission "gnu.io.ParallelPorts", "read";</li>
  <li>permission java.util.PropertyPermission "gnu.io.rxtx.ParallelPorts", "read";</li>
  <li>permission java.lang.RuntimePermission "modifyThreadGroup";</li>
  <li>permission java.lang.RuntimePermission "modifyThread";</li>
  </ul>
  
  <p>The first line and second is different from ubuntu,when the ubuntu is:</p>
  
  <ul>
  <li>permission java.lang.RuntimePermission "loadLibrary.librxtxSerial";</li>
  <li>permission java.io.FilePermission "${java.home}${/}lib${/}amd64${/}librxtxSerial.so", "read";</li>
  </ul>