JAVA-通过接口读取本地jar包,并调用其中实现了接口的类中的方法




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

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM