title: Creating a JTwain applet in Eclipse
body: <p>I'm doing a bit of testing with the JTwain Library. I need to attach scanning functionality to a Django App. I've got a bit of code that will run locally but I can't make it work in an applet. </p>
  
  <p>I'm back, trying to get the demo applet to run. I've created an eclipse 'runable jar' (I've had to add a dummy Main to one of the classes). And I'm getting the following output from the plugin console when I load the page in a browser - </p>
  
  <pre><code>    java.security.AccessControlException: access denied (java.lang.RuntimePermission loadLibrary.AspriseJTwain)
      at java.security.AccessControlContext.checkPermission(Unknown Source)
      at java.security.AccessController.checkPermission(Unknown Source)
      at java.lang.SecurityManager.checkPermission(Unknown Source)
      at java.lang.SecurityManager.checkLink(Unknown Source)
      at java.lang.Runtime.loadLibrary0(Unknown Source)
      at java.lang.System.loadLibrary(Unknown Source)
      at com.asprise.util.jtwain.SourceManager.init(SourceManager.java:222)
      at com.asprise.util.jtwain.SourceManager.&lt;init&gt;(SourceManager.java:36)
      at com.asprise.util.jtwain.SourceManager.instance(SourceManager.java:28)
      at JTwainApplet.scan(JTwainApplet.java:39)
      at JTwainApplet.init(JTwainApplet.java:69)
      at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
  java.lang.UnsatisfiedLinkError: com.asprise.util.jtwain.lowlevel.Control.performAction(ILjava/lang/Object;)Z
      at com.asprise.util.jtwain.lowlevel.Control.performAction(Native Method)
      at com.asprise.util.jtwain.lowlevel.Control.unloadSourceManager(Control.java:93)
      at com.asprise.util.jtwain.SourceManager.closeSourceManager(SourceManager.java:120)
      at JTwainApplet.scan(JTwainApplet.java:57)
      at JTwainApplet.init(JTwainApplet.java:69)
      at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
  Scan
  </code></pre>
  
  <p>Below is the structure of the Jar I've created.</p>
  
  <pre><code>C:\PythonProjects\CacheProject\media\java&gt;jar tf demo.jar
  META-INF/MANIFEST.MF
  JTwainApplet.class
  ImageDisplayer$1.class
  ImageDisplayer.class
  META-INF/
  META-INF/ASPRISE.DSA
  com/
  com/asprise/
  com/asprise/util/
  com/asprise/util/jtwain/
  com/asprise/util/jtwain/ImageGenerator.class
  com/asprise/util/jtwain/InvalidStateException.class
  com/asprise/util/jtwain/JTwainConstants.class
  com/asprise/util/jtwain/JTwainException.class
  com/asprise/util/jtwain/OperationException.class
  com/asprise/util/jtwain/Source.class
  com/asprise/util/jtwain/SourceManager.class
  com/asprise/util/jtwain/lowlevel/
  com/asprise/util/jtwain/lowlevel/Capability.class
  com/asprise/util/jtwain/lowlevel/Control.class
  com/asprise/util/jtwain/lowlevel/DataType.class
  com/asprise/util/jtwain/lowlevel/DataTypeIdentity.class
  com/asprise/util/jtwain/lowlevel/DataTypeImageInfo.class
  com/asprise/util/jtwain/lowlevel/DataTypeImageLayout.class
  com/asprise/util/jtwain/lowlevel/DataTypeVersion.class
  com/asprise/util/jtwain/lowlevel/ItemType.class
  com/asprise/util/jtwain/lowlevel/ItemTypeFix32.class
  com/asprise/util/jtwain/lowlevel/ItemTypeFrame.class
  com/asprise/util/jtwain/lowlevel/ItemTypeInteger.class
  com/asprise/util/jtwain/lowlevel/ItemTypeString.class
  com/asprise/util/jtwain/lowlevel/OperationResult.class
  com/asprise/util/jtwain/lowlevel/ValueContainer.class
  com/asprise/util/jtwain/lowlevel/ValueContainerArray.class
  com/asprise/util/jtwain/lowlevel/ValueContainerEnumeration.class
  com/asprise/util/jtwain/lowlevel/ValueContainerOneValue.class
  com/asprise/util/jtwain/lowlevel/ValueContainerRange.class
  com/asprise/util/jtwain/web/
  com/asprise/util/jtwain/web/FileUploader.class
  com/asprise/util/jtwain/web/ImageDisplayPanel.class
  com/asprise/util/jtwain/web/UploadApplet.class
  com/asprise/util/jtwain/web/UploadApplet_buttonCheckJTwain_actionAdapter.class
  com/asprise/util/jtwain/web/UploadApplet_buttonInstallJVM_actionAdapter.class
  com/asprise/util/jtwain/web/UploadApplet_buttonScan_actionAdapter.class
  com/asprise/util/jtwain/web/UploadApplet_buttonUpload_actionAdapter.class
  com/asprise/util/jtwain/web/UploadApplet_labelURL_mouseAdapter.class
  com/asprise/util/jtwain/web/UploadApplet_useProxy_actionAdapter.class
  </code></pre>
  
  <p>And here's the Code for the JTwainApplet</p>
  
  <pre><code>    import java.applet.Applet;
  import java.awt.HeadlessException;
  import java.awt.Image;
  
  import com.asprise.util.jtwain.Source;
  import com.asprise.util.jtwain.SourceManager;
  
  /*
   * $Id$
   * 
   */
  
  /**
   * @author  JACK    (Jan 19, 2004)
   */
  public class JTwainApplet extends Applet {
  
      /**
       * @throws java.awt.HeadlessException
       */
      public JTwainApplet() throws HeadlessException {
          super();
          // TODO Auto-generated constructor stub
      }
  
      public static void main(String[] args) {
      }
      /* (non-Javadoc)
       * @see java.applet.Applet#destroy()
       */
      public void destroy() {
          // TODO Auto-generated method stub
          super.destroy();
      }
  
      public void scan() {
              try {
                  // SourceManager.setLibraryPath("E:\\Twain\\Asprise\\JT\\Debug\\JT.dll");
                  Source source = SourceManager.instance().getDefaultSource();
  
                  if(source == null) {
                      System.err.println("There is no (default) source on the system!");
                      return;
                  }
  
                  source.open();
  
                  Image image = source.acquireImage();
  
                  new ImageDisplayer("DemoSimple", image);
  
                  source.close();
  
              }catch(Exception e) {
                  e.printStackTrace();
              }finally{
                  SourceManager.closeSourceManager();
              }
      }
  
      /* (non-Javadoc)
       * @see java.applet.Applet#init()
       */
      public void init() {
          super.init();
  
          System.out.println("Init.");
  
          scan();
  
          System.out.println("Scan");
      }
  
      /* (non-Javadoc)
       * @see java.applet.Applet#start()
       */
      public void start() {
          // TODO Auto-generated method stub
          super.start();
      }
  
      /* (non-Javadoc)
       * @see java.applet.Applet#stop()
       */
      public void stop() {
          // TODO Auto-generated method stub
          super.stop();
      }
  
  }
  </code></pre>
  
  <p>Lastly my jnpl and html source</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;jnlp spec="1.0+" codebase="" href=""&gt;
      &lt;information&gt;
          &lt;title&gt;Cache Scanning&lt;/title&gt;
          &lt;vendor&gt;Altcom&lt;/vendor&gt;
      &lt;/information&gt;
      &lt;resources&gt;
          &lt;!-- Application Resources --&gt;
          &lt;j2se version="1.6+"
                href="http://java.sun.com/products/autodl/j2se" /&gt;
          &lt;jar href="http://127.0.0.1:18123/media/java/demo.jar" main="true" /&gt;
      &lt;/resources&gt;
      &lt;applet-desc 
           name="JTwain Applet Demo"
           main-class="JTwainApplet"
           width="500"
           height="200"&gt;
       &lt;/applet-desc&gt;
       &lt;update check="background"/&gt;
  &lt;/jnlp&gt; 
  
  
  
     **javascript** - 
   &lt;script src="http://java.com/js/deployJava.js"&gt;&lt;/script&gt;    
      &lt;script&gt; 
          var attributes = { code: "http://127.0.0.1:18123/media/java/demo.jar",  width:500, height:200} ; 
          var parameters = {jnlp_href: "http://127.0.0.1:18123/media/java/demo.jnlp"} ; 
          deployJava.runApplet(attributes, parameters, '1.6'); 
      &lt;/script&gt;
  </code></pre>
  
  <p>Any suggestions would be greatfully recieved. This is driving me nuts.</p>