public static void main(String[] args) throws MalformedURLException, ClassNotFoundException { Policy.setPolicy(new PluginSecurityPolicy()); System.setSecurityManager(new SecurityManager()); PluginClassLoader urlCL = new PluginClassLoader(new File( "A Jar containing images/load.gif and SampleApp class").toURL()); Class<?> loadClass = urlCL.loadClass("net.sourceforge.marathon.examples.SampleApp"); System.out.println(loadClass); System.out.println("Loading the class using the class loader object. Resource = " + urlCL.getResource("images/load.gif")); System.out.println("Loading the class using the class loader object with absolute path. Resource = " + urlCL.getResource("/images/load.gif")); System.out.println("Loading the class using the class object. Resource = " + loadClass.getResource("images/load.gif")); }
/** * Reads the plugin into an object. This method will fail if the plugin is not valid. * This could happen if the file is not a java archive, or if the plugin spec file is * missing from the archive, etc. */ protected Plugin readPluginFile(PluginCoordinates coordinates, File pluginFile) throws Exception { try { PluginClassLoader pluginClassLoader = createPluginClassLoader(pluginFile); URL specFile = pluginClassLoader.getResource(PluginUtils.PLUGIN_SPEC_PATH); if (specFile == null) { throw new Exception(Messages.i18n.format("DefaultPluginRegistry.MissingPluginSpecFile", PluginUtils.PLUGIN_SPEC_PATH)); //$NON-NLS-1$ } else { PluginSpec spec = PluginUtils.readPluginSpecFile(specFile); Plugin plugin = new Plugin(spec, coordinates, pluginClassLoader); // TODO use logger when available System.out.println("Read apiman plugin: " + spec); //$NON-NLS-1$ return plugin; } } catch (Exception e) { throw new Exception(Messages.i18n.format("DefaultPluginRegistry.InvalidPlugin", pluginFile.getAbsolutePath()), e); //$NON-NLS-1$ } }
/** * Reads the plugin into an object. This method will fail if the plugin is not valid. * This could happen if the file is not a java archive, or if the plugin spec file is * missing from the archive, etc. */ protected Plugin readPluginFile(PluginCoordinates coordinates, File pluginFile) throws Exception { try { PluginClassLoader pluginClassLoader = createPluginClassLoader(pluginFile); URL specFile = pluginClassLoader.getResource(PluginUtils.PLUGIN_SPEC_PATH); if (specFile == null) { throw new Exception(Messages.i18n.format("DefaultPluginRegistry.MissingPluginSpecFile", PluginUtils.PLUGIN_SPEC_PATH)); //$NON-NLS-1$ } else { PluginSpec spec = PluginUtils.readPluginSpecFile(specFile); Plugin plugin = new Plugin(spec, coordinates, pluginClassLoader); // TODO use logger when available System.out.println("Read apiman plugin: " + spec); //$NON-NLS-1$ return plugin; } } catch (Exception e) { throw new Exception(Messages.i18n.format("DefaultPluginRegistry.InvalidPlugin", pluginFile.getAbsolutePath()), e); //$NON-NLS-1$ } }
throw new InvalidPluginException(Messages.i18n.format("AbstractPluginRegistry.InvalidPlugin", pluginFile.getAbsolutePath()), e); //$NON-NLS-1$ URL specFile = pluginClassLoader.getResource(PluginUtils.PLUGIN_SPEC_PATH); if (specFile == null) { throw new InvalidPluginException(Messages.i18n.format("AbstractPluginRegistry.MissingPluginSpecFile", PluginUtils.PLUGIN_SPEC_PATH)); //$NON-NLS-1$