title: iaik pkcs#11 wrapper and java.lang.NoSuchMethodError
body: <p>I am trying to run a simple sample code from iaik pkcs#11 wrapper (version 1.3, the latest atm) but get <code>NoSuchMethodError</code> on <code>pkcs11Module.initialize</code> call.</p>
  
  <pre><code>Module pkcs11Module = Module.getInstance("siecap11");
  pkcs11Module.initialize(null); 
  Slot[] slots = pkcs11Module.getSlotList(Module.SlotRequirement.TOKEN_PRESENT);
  for (Slot s: slots) {
      System.out.println(s.getSlotID());
  }
  pkcs11Module.finalize(null);
  </code></pre>
  
  <p>Exception stack trace is as following</p>
  
  <pre><code>java.lang.NoSuchMethodError:     iaik.pkcs.pkcs11.wrapper.PKCS11.C_Initialize(Ljava/lang/Object;Z)V
  at iaik.pkcs.pkcs11.Module.initialize(Module.java:308)
  at test.pkcs11.Pkcs11Service.listSlotsWithTokens(Pkcs11Service.java:98)
  at test.pkcs11.TestPkcs11Service.testListSlots(TestPkcs11Service.java:35)
  </code></pre>
  
  <p>A similar code works fine on Linux, so i am guessing there is something wrong with pkcs11wrapper.dll.</p>
  
  <p><code>pkcs11wrapper.dll</code> and <code>siecap11.dll</code> are in <code>c\windows\system32</code> directory and both are 32bit modules.</p>
  
  <p>I have tried a different pkcs#11 provider, debug and release versions of pkcs11wrapper but the result was the same.</p>
  
  <p>The debug version of the pkcs11wrapper.dll generates the following output:</p>
  
  <pre><code>11/26/13 21:30:50   CALL: entering (in Java_iaik_pkcs_pkcs11_wrapper_PKCS11Implementation_initializeLibrary)
  11/26/13 21:30:50   CALL: exiting  (in Java_iaik_pkcs_pkcs11_wrapper_PKCS11Implementation_initializeLibrary)
  11/26/13 21:30:50   CALL: entering (in Java_iaik_pkcs_pkcs11_wrapper_PKCS11Implementation_connect)
  11/26/13 21:30:50   INFO: connect to PKCS#11 module: siecap11 ...  (in Java_iaik_pkcs_pkcs11_wrapper_PKCS11Implementation_connect)
  11/26/13 21:30:50   CALL: exiting  (in Java_iaik_pkcs_pkcs11_wrapper_PKCS11Implementation_connect)
  </code></pre>
  
  <p>The utility applications that came with the smart cards work fine, so is opensc pkcs11-tool.</p>
  
  <p>EDIT:</p>
  
  <p>Using version 1.2.17 of pkcs11 wrapper library and its accompanying dll, the code above works without a problem. But the original question remains unresolved.</p>
  
  <p>EDIT2:</p>
  
  <p>Following code, suggested by SubOptimal generates the following output.</p>
  
  <pre><code>@Test
  public void testFindLibrary() {
      String lineSeparator = System.getProperty("path.separator");
      String libraryPath = System.getProperty("java.library.path");
      for (String dir : libraryPath.split(lineSeparator)) {
          File f = new File(dir + "/" + "pkcs11wrapper.dll"); 
          if (f.exists()) {
              System.out.println("found in: " + f.getAbsolutePath());
          }
      }
  }
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>found in: C:\Windows\system32\pkcs11wrapper.dll
  found in: C:\Windows\system32\pkcs11wrapper.dll
  found in: C:\Windows\system32\pkcs11wrapper.dll
  </code></pre>