URLClassLoader
) can not load classes which are in jar files nested inside archives.
sun.net.www.ParseUtil
classURLClassLoader
class, but contrary to the URLClassLoader, you can load classes which are in jar files nested inside archives.zipfile.zip - TestEmbed.jarand the the
TestEmbed.jar
jar file containing the org.testutils.embed.EmbeddedClass
class with a no argument constructor.File zipFile = new File("zipfile.zip"); URL zipURL = zipFile.toURI().toURL(); URL jarURL = FileUtilities.getJarEntryURL(zipURL, "TestEmbed.jar"); URL[] urls = new URL[1]; urls[0] = jarURL; NestedURLClassLoader loader = new NestedURLClassLoader(urls); Class clazz = Class.forName("org.testutils.embed.EmbeddedClass", true, loader); Object o = clazz.newInstance();
excludingFilter
is true: packages which are in the Set will be loaded using the default behavior of the URLClassLoader
, all other packages will be loaded using the special behavior of this ClassexcludingFilter
is false: packages which are not in the set will be loaded using the default behavior of the URLClassLoader
, all packages in the Set will be loaded using the special behavior of this ClassCopyright 2006-2024 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences