首页 > 编程语言 > 详细

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

时间:2019-01-07 19:55:15      阅读:601      评论:0      收藏:0      [点我收藏+]


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包,并调用其中实现了接口的类中的方法

原文:https://www.cnblogs.com/a77355699/p/10234939.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!