标签:ons catch reflect on() sof loader jar end you
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(); } });
JAVA-通过接口读取本地jar包,并调用其中实现了接口的类中的方法
标签:ons catch reflect on() sof loader jar end you
原文地址:https://www.cnblogs.com/a77355699/p/10234939.html