public void initialize(String libDir) throws Exception { File dependencyDirectory = new File(libDir); File[] files = dependencyDirectory.listFiles(); ArrayList<URL> urls = new ArrayList<URL>(); for (int i = 0; i < files.length; i++) { if (files[i].getName().endsWith(".jar")) { urls.add(files[i].toURL()); //urls.add(files[i].toURI().toURL()); } } classLoader = new JarFileClassLoader("Scheduler CL" + System.currentTimeMillis(), urls.toArray(new URL[urls.size()]), GFClassLoader.class.getClassLoader()); }
/** * Creates a JarFileClassLoader that is a child of the system class loader. * @param name the name of this class loader * @param urls a list of URLs from which classes and resources should be loaded */ public JarFileClassLoader(String name, URL[] urls) { super(name, EMPTY_URLS); addURLs(urls); }
private boolean isSealed(Attributes packageAttributes, Attributes mainAttributes) { String sealed = getAttribute(Attributes.Name.SEALED, packageAttributes, mainAttributes); if (sealed == null) { return false; } return "true".equalsIgnoreCase(sealed); } }
JarFileClassLoader tempClassLoader = null; try { tempClassLoader = new JarFileClassLoader(null, urls, parentClassLoader); List<Class<?>> classes = new ArrayList<Class<?>>(); for (URL url : urlList) { } finally { if (tempClassLoader != null) { tempClassLoader.destroy();
mainAttributes = manifest.getMainAttributes(); Package pkg = getPackage(packageName); if (pkg != null) { if (pkg.isSealed()) { if (isSealed(packageAttributes, mainAttributes)) { throw new SecurityException("Package was already been loaded and not sealed: package=" + packageName + ", url=" + jarUrl); String specTitle = getAttribute(Attributes.Name.SPECIFICATION_TITLE, packageAttributes, mainAttributes); String specVendor = getAttribute(Attributes.Name.SPECIFICATION_VENDOR, packageAttributes, mainAttributes); String specVersion = getAttribute(Attributes.Name.SPECIFICATION_VERSION, packageAttributes, mainAttributes); String implTitle = getAttribute(Attributes.Name.IMPLEMENTATION_TITLE, packageAttributes, mainAttributes); String implVendor = getAttribute(Attributes.Name.IMPLEMENTATION_VENDOR, packageAttributes, mainAttributes); String implVersion = getAttribute(Attributes.Name.IMPLEMENTATION_VERSION, packageAttributes, mainAttributes); if (isSealed(packageAttributes, mainAttributes)) { sealBase = jarUrl; definePackage(packageName, specTitle, specVersion, specVendor, implTitle, implVersion, implVendor, sealBase);
definePackage(className, codeSourceUrl, manifest); Class clazz = defineClass(className, bytes, 0, bytes.length, codeSource); return clazz;
protected ClassLoader getParentClassLoader(SpringApplicationContext applicationContext) { List<ClassLoader> parents = new ArrayList<ClassLoader>(); parents.add(super.getParentClassLoader(applicationContext)); for (Bundle bundle : bundleContext.getBundles()) { try { String symbolicName = bundle.getSymbolicName(); if (symbolicName.contains("camel-spring") || symbolicName.contains("camel-osgi") || symbolicName.contains("camel-cxf")) { parents.add(BundleDelegatingClassLoader.createBundleClassLoaderFor(bundle)); } } catch (Throwable e) { // Do nothing } } return new JarFileClassLoader("SU parent class loader", new URL[0], parents.toArray(new ClassLoader[parents.size()])); } }
/** * Creates a JarFileClassLoader that is a child of the specified class loader. * @param name the name of this class loader * @param urls a list of URLs from which classes and resources should be loaded * @param parent the parent of this class loader */ public JarFileClassLoader(String name, URL[] urls, ClassLoader parent) { super(name, EMPTY_URLS, parent); addURLs(urls); }
ClassLoader cl = new JarFileClassLoader( "Component ClassLoader", (URL[]) urls.toArray(new URL[urls.size()]),
/** * Creates a named class loader as a child of the specified parents. * @param name the name of this class loader * @param urls the urls from which this class loader will classes and resources * @param parents the parents of this class loader */ public JarFileClassLoader(String name, URL[] urls, ClassLoader[] parents) { super(name, EMPTY_URLS, parents); addURLs(urls); }
private ClassLoader createClassLoader() { boolean parentFirst = library.isParentFirstClassLoaderDelegation(); // Make the current ClassLoader the parent ClassLoader parent = getClass().getClassLoader(); ClassPath cp = library.getSharedLibraryClassPath(); String[] classPathNames = cp.getPathElements(); URL[] urls = new URL[classPathNames.length]; for (int i = 0; i < classPathNames.length; i++) { File file = new File(installationDir, classPathNames[i]); try { urls[i] = file.toURL(); } catch (MalformedURLException e) { throw new IllegalArgumentException(classPathNames[i], e); } } return new JarFileClassLoader( library.getIdentification().getName(), urls, parent, !parentFirst, new String[0], new String[] {"java.", "javax." }); }
public JarFileClassLoader(String name, URL[] urls, ClassLoader[] parents, boolean inverseClassLoading, Collection hiddenClasses, Collection nonOverridableClasses) { super(name, EMPTY_URLS, parents, inverseClassLoading, hiddenClasses, nonOverridableClasses); addURLs(urls); }
classLoader = new JarFileClassLoader(applicationContext.getDisplayName(), urls, parentLoader,
public JarFileClassLoader(String name, URL[] urls, ClassLoader[] parents, boolean inverseClassLoading, String[] hiddenClasses, String[] nonOverridableClasses) { super(name, EMPTY_URLS, parents, inverseClassLoading, hiddenClasses, nonOverridableClasses); addURLs(urls); }
classLoader = new JarFileClassLoader(applicationContext.getDisplayName(), urls, parents.toArray(new ClassLoader[parents.size()]),
public JarFileClassLoader(String name, URL[] urls, ClassLoader parent, boolean inverseClassLoading, String[] hiddenClasses, String[] nonOverridableClasses) { super(name, EMPTY_URLS, parent, inverseClassLoading, hiddenClasses, nonOverridableClasses); addURLs(urls); }
classLoader = new JarFileClassLoader(applicationContext.getDisplayName(), urls, parents.toArray(new ClassLoader[parents.size()]),
new JarFileClassLoader("JarFileClassLoader for lib: " + libraryAndVersion, new URL[] { libraryLocation }));
URL[] urls = getDefaultLocations(); ClassLoader parentLoader = getParentClassLoader(applicationContext); classLoader = new JarFileClassLoader(applicationContext.getDisplayName(), urls, parentLoader);
URL[] urls = getDefaultLocations(); ClassLoader parentLoader = getParentClassLoader(applicationContext); classLoader = new JarFileClassLoader(applicationContext.getDisplayName(), urls, parentLoader);