use of java.net.URLClassLoader in project vert.x by eclipse.
the class ServiceHelperTest method loadFactoriesFromTCCL.
@Test
public void loadFactoriesFromTCCL() throws Exception {
ClassLoader custom = new URLClassLoader(new URL[] { new File("target/externals").toURI().toURL() });
// Try without the TCCL classloader.
Collection<SomeFactory> factories = ServiceHelper.loadFactories(SomeFactory.class);
assertThat(factories).isNotNull().hasSize(0);
// Try with the TCCL classloader
final ClassLoader originalTCCL = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(custom);
factories = ServiceHelper.loadFactories(SomeFactory.class);
assertThat(factories).isNotNull().hasSize(1);
assertThat(factories.iterator().next().classloader()).isEqualTo(custom);
} finally {
Thread.currentThread().setContextClassLoader(originalTCCL);
}
}
use of java.net.URLClassLoader in project vert.x by eclipse.
the class ServiceCommandLoaderTest method testNoCommandsWhenLoadedFromEmptyClassloader.
@Test
public void testNoCommandsWhenLoadedFromEmptyClassloader() {
ClassLoader classLoader = new URLClassLoader(new URL[0], null);
// We see the implementation from the classpath
loader = new ServiceCommandFactoryLoader(classLoader);
assertThat(loader.lookup()).isNotEmpty();
}
use of java.net.URLClassLoader in project vert.x by eclipse.
the class MetricsOptionsTest method createMetricsFromMetaInfLoader.
static ClassLoader createMetricsFromMetaInfLoader(String factoryFqn) {
return new URLClassLoader(new URL[0], Thread.currentThread().getContextClassLoader()) {
@Override
public Enumeration<URL> findResources(String name) throws IOException {
if (name.equals("META-INF/services/io.vertx.core.spi.VertxMetricsFactory")) {
File f = File.createTempFile("vertx", ".txt");
f.deleteOnExit();
Files.write(f.toPath(), factoryFqn.getBytes());
return Collections.enumeration(Collections.singleton(f.toURI().toURL()));
}
return super.findResources(name);
}
};
}
use of java.net.URLClassLoader in project vert.x by eclipse.
the class NestedRootJarResolverTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
// This folder is inside the nested-inf/classes directory, inside nestedroot.jar
webRoot = "webroot2";
prevCL = Thread.currentThread().getContextClassLoader();
URL jarUrl = prevCL.getResource("nestedroot.jar");
URL rootUrl = new URL("jar:" + jarUrl + "!/nested-inf/classes!/");
URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { rootUrl }, prevCL);
Thread.currentThread().setContextClassLoader(urlClassLoader);
}
use of java.net.URLClassLoader in project elasticsearch by elastic.
the class JarHell method checkJarHell.
/**
* Checks the current classpath for duplicate classes
* @throws IllegalStateException if jar hell was found
*/
public static void checkJarHell() throws IOException, URISyntaxException {
ClassLoader loader = JarHell.class.getClassLoader();
Logger logger = Loggers.getLogger(JarHell.class);
if (logger.isDebugEnabled()) {
logger.debug("java.class.path: {}", System.getProperty("java.class.path"));
logger.debug("sun.boot.class.path: {}", System.getProperty("sun.boot.class.path"));
if (loader instanceof URLClassLoader) {
logger.debug("classloader urls: {}", Arrays.toString(((URLClassLoader) loader).getURLs()));
}
}
checkJarHell(parseClassPath());
}
Aggregations