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(); } });

  

相关文章:

  • 2021-11-29
  • 2021-11-20
  • 2021-04-20
  • 2021-12-31
  • 2022-12-23
  • 2022-02-12
  • 2021-10-26
  • 2021-10-27
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-16
  • 2021-06-16
  • 2021-08-03
  • 2021-08-21
  • 2022-12-23
相关资源
相似解决方案