PluginClassLoader extends URLClassLoader { public static PluginClassLoader newInstance(final PluginFile file) throws IOException { if (file == null) throw new NullPointerException("The plugin can not be null"); try (final ZipFile zipFile = new ZipFile(file)) { final URL[] urls = zipFile.stream() .filter(onlyFiles()) .map(entry -> entryToUrl(file, entry)) .filter(Objects::nonNull) .collect(Collectors.toList()) .toArray(new URL[0]); return new PluginClassLoader(urls); } } private  PluginClassLoader(URL[] urls); static PluginClassLoader newInstance(final PluginFile file);  }
@Test void testGetClass() throws IOException, ClassNotFoundException { final PluginClassLoader pluginClassLoader = PluginClassLoader.newInstance(PLUGIN_FILE); final Class<?> clazz = pluginClassLoader.loadClass("com.twasyl.slideshowfx.dummy.plugin.Dummy"); assertAll( () -> assertNotNull(clazz), () -> assertEquals("com.twasyl.slideshowfx.dummy.plugin.Dummy", clazz.getName())); }
@Test void testGetResource() throws IOException, ClassNotFoundException { final PluginClassLoader pluginClassLoader = PluginClassLoader.newInstance(PLUGIN_FILE); final Class<?> clazz = pluginClassLoader.loadClass("com.twasyl.slideshowfx.dummy.plugin.Dummy"); final URL resource = clazz.getResource("/com/twasyl/slideshowfx/dummy/plugin/Application.fxml"); assertNotNull(resource); }