PluginUtils { public static ArrayList<Class<? extends Plugin>> getPluginsFromExternalJar(File pluginJar, Class pluginType) throws MalformedURLException { URL[] urlArray = new URL[1]; urlArray[0] = pluginJar.toURI().toURL(); URLClassLoader childJar = new URLClassLoader(urlArray); Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(urlArray).addClassLoader(childJar)); ArrayList<Class<? extends Plugin>> csfi = new ArrayList(reflections.getSubTypesOf(pluginType)); ArrayList<Class<? extends Plugin>> toReturn = new ArrayList<>(); for (Class<? extends Plugin> c : csfi) { if (!Modifier.isAbstract(c.getModifiers())) { toReturn.add(c); logger.debug("Read class: " + c.getCanonicalName() + " from jar: " + pluginJar.getAbsolutePath()); } } return toReturn; }  static File[] getPluginJars(); static ArrayList<Class<? extends Plugin>> getPluginsFromExternalJar(File pluginJar, Class pluginType);  }
@Test public void testGetPluginsFromExternalJar() throws Exception { System.out.println("getPluginsFromExternalJar"); File pluginJar = new File("./src/test/resources", "plugin-test-notify.jar"); System.out.print("Looking for plugin jar at: " + pluginJar.getAbsolutePath()); assertTrue(pluginJar.exists()); Class moduleType = NotifierPlugin.class; ArrayList<Class<? extends Plugin>> result = PluginUtils.getPluginsFromExternalJar(pluginJar, moduleType); assertNotNull(result); assertEquals(2, result.size()); assertNotNull(result.get(0)); assertTrue(result.get(0).getCanonicalName().startsWith("com.patriotcoder.testdocussandraplugin.TestNotifierPlugin")); }