title: Designing an API - troubles with class loading (Groovy)
body: <p>It's my first time designing an API. I have a program with folder 'plugins'. I made a test plugin in that folder packaged in JAR. In the program I have a Groovy class 'Configuration', which is supposed to load the plugins.</p>
  
  <p><code>Configuration.java</code>:</p>
  
  <pre><code>static void processConfiguration()
  {
          File pluginDirectory=new File(PLUGINDIRECTORY)//it's 'plugins'
          if(!pluginDirectory.exists()) pluginDirectory.mkdir()
          File[] pluginfiles=pluginDirectory.listFiles()
  
          for(File f:pluginfiles)
          {
              if(f.name.endsWith('.jar'))
              {
                  JarFile jar=new JarFile(f)
  
                  for(JarEntry jarEntry:jar.entries())
                  {
                      if(jarEntry.getName().endsWith('.class'))
                      {
                          //try loading the class   
                      }
                  }
  
  
              }
          }
  }
  </code></pre>
  
  <p>So, I tried doing these at the <code>//try loading the class</code> block</p>
  
  <p><code>Class cl=ClassLoader.getSystemClassLoader().loadClass(jarEntry.name)</code></p>
  
  <p><code>Class cl=new GroovyClassLoader().loadClass(jarEntry.name)</code></p>
  
  <p><code>Class cl=Configuration.classLoader.loadClass(jarEntry.name)</code></p>
  
  <p><code>Class cl=Class.forName(jarEntry.getName())</code></p>
  
  <p>also tried with replacing - <code>jarEntry.name.replaceAll('/','.').replace('.class','')</code>, but I think it's done automatically.
  Getting Class not found exception:</p>
  
  <pre><code>Exception in Application start method
  java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
      at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
  Caused by: java.lang.RuntimeException: Exception in Application start method
      at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
      at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: java.lang.ClassNotFoundException: jace/plugins/JavaPlugin.class
      at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      at java_lang_ClassLoader$loadClass.call(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
      at jace.Configuration.processConfiguration(Configuration.groovy:87)
      at jace.Jace.start(Jace.java:56)
      at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
      at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
      at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
      at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
      at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
      at  com.sun.glass.ui.gtk.GtkApplication.lambda$null$49(GtkApplication.java:139)
  </code></pre>