1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| @Slf4j public class URLClassLoaderTest { private static final String remoteJarPath = "http://localhost:8080/operators/base-operator.jar"; @Test public void testLoadRemoteJar() throws Exception { URI uri = new URI(remoteJarPath); URLClassLoader classLoader = new URLClassLoader(new URL[]{uri.toURL()}); Thread.currentThread().setContextClassLoader(classLoader); ServiceLoader<Operator> loader = ServiceLoader.load(Operator.class); Iterator<Operator> iterator = loader.iterator(); while (iterator.hasNext()) { try { Operator operator = iterator.next(); log.info("OperatorInfo: name={}, platform={}", operator.getName(), operator.getPlatform()); } catch (Exception e) { log.warn("Failed to instantiate operator", e); } } } }
|