简体   繁体   English

从目录中的jar加载扩展了另一个类的类

[英]Loading classes that extend another class from jars in directory

What I want to do is , let's say I have a folder , and that is a directory, and let's say I created a JAR that has a class in there that is extending "Apple". 我想做的是,假设我有一个文件夹,这是一个目录,并且假设我创建了一个JAR,其中包含一个扩展“ Apple”的类。 How would I check ALL JARS in that folder and check that they have class extending Apple, THEN add each and every one of those classes extending apple to my List? 我如何检查该文件夹中的所有JARS,并检查它们是否具有扩展Apple的类,然后将扩展Apple的每个类添加到我的列表中?

You have to use reflection API for this. 您必须为此使用反射API。 First, get list of all classes loaded by class loader and then with the help of reflection API, you can check if a class extends Apple or not. 首先,获取由类加载器加载的所有类的列表,然后在反射API的帮助下,您可以检查类是否扩展了Apple。 Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM