title: Dynamically loading a JAR on a maven based project
body: <p>I am trying to fix this exception: Cannot load 64-bit SWT libraries on 32-bit JVM</p>
  
  <p>My project is maven based and I declared both dependencies (SWT 32 bit and SWT 64 bit) in the pom.xml file.</p>
  
  <p>I am trying to dynamically load the correct JAR based on the Java architecture data model (sun.arch.data.model property) using the following function:</p>
  
  <pre><code>private static synchronized void loadLibrary(File jar) {
      try {
          URLClassLoader loader = (URLClassLoader) ClassLoader.getSystemClassLoader();
          URL url = jar.toURI().toURL();
  
          for (URL it : Arrays.asList(loader.getURLs())) {
              if (it.equals(url)) {
                  return;
              }
          }
  
          Method method = URLClassLoader.class.getDeclaredMethod("addURL", new Class[]{URL.class});
          method.setAccessible(true);
          method.invoke(loader, new Object[]{url});
      } catch (Exception e) {
          System.out.println("error");
      }
  }
  </code></pre>
  
  <p>The problem is that I don't know how to specify the path to the JAR. I see the JAR is downloaded in the .m2 folder but I guess that I can't specify that path. My guess is that I should specify the path to the Java cache were JNLP will download the JARs. Am I correct?</p>