URLClassLoader classLoader = new URLClassLoader(new URL[]{new URL("jar 本地路径,例如:file:D:/project/inputsplit-1.0-SNAPSHOT.jar")}, Thread.currentThread().getContextClassLoader());
Reflections reflections = new Reflections("your interface package", classLoader);
Set<Class<? extends "your interface">> subTypesOf = reflections.getSubTypesOf("your interface");
//从继承中获取任意实现
subTypesOf.stream().findAny().ifPresent(clazz -> {
try {
"your interface" interface = clazz.newInstance();
} catch (Exception e) {
throw new RuntimeException();
}
});