title: Fix the: java.lang.UnsatisfiedLinkError: no attach in java.library.path
body: <p>I am trying to get a list of all the VMs running on my machine using the Attach API.</p>
  
  <p>This is the code i am using:</p>
  
  <pre><code>import java.lang.reflect.Field;
  import java.util.List;
  import com.sun.tools.attach.*;
  
  public class JVMListManager 
  {
      static String pathToAdd = "C:/Program Files/Java/jdk1.7.0_03/jre/bin/attach.dll";
      public static void setLibraryPath(String path) throws Exception {
          System.setProperty( "java.library.path", pathToAdd );
  
          Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
          fieldSysPath.setAccessible(true);
          fieldSysPath.set(null, null);
      }
  
      private void listActiveVM()
      {
          List&lt;VirtualMachineDescriptor&gt; vm = VirtualMachine.list();
          int i= 1;
          for(VirtualMachineDescriptor vmD : vm)
          {
              System.out.println(i + ". " + vmD.displayName());
              i++;
          }
      }
  
      public static void main(String[] args) throws Exception
      {
          setLibraryPath(pathToAdd);
  
          JVMListManager jvmListManager = new JVMListManager();
          jvmListManager.listActiveVM();
      }
  }
  </code></pre>
  
  <p>ERROR: </p>
  
  <blockquote>
    <p>java.util.ServiceConfigurationError:
    com.sun.tools.attach.spi.AttachProvider: Provider
    sun.tools.attach.WindowsAttachProvider could not be instantiated:
    java.lang.UnsatisfiedLinkError: no attach in java.library.path</p>
  </blockquote>
  
  <p>Please let me know what methods i can use to fix this. </p>
  
  <p>I have also tried using System.load(pathToAdd);
  Also i have referred to this <a href="http://fahdshariff.blogspot.jp/2011/08/changing-java-library-path-at-runtime.html">Blog post</a>, but it does not work. :'(</p>