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". 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?
Asked
Active
Viewed 521 times
1
-
1This [link](http://stackoverflow.com/questions/205573/at-runtime-find-all-classes-in-a-java-application-that-extend-a-base-class) may help you. And see also google's [reflections](https://code.google.com/p/reflections/) – Wundwin Born Jun 27 '14 at 05:14
-
@Wundwin: any alternatives to google reflections – Gaurav Jan 29 '19 at 07:24
1 Answers
1
You have to use reflection API for this. 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. Hope this helps

Gaurav
- 296
- 1
- 6
- 21

Programmer
- 325
- 5
- 18
-
1Can I have an example on how to to that? I've never use class loaders or tinkered with reflection. – user3529775 Jun 27 '14 at 04:38
-
1Please refer to below link: http://stackoverflow.com/questions/3222638/get-all-of-the-classes-in-the-classpath and http://stackoverflow.com/questions/3504870/how-to-test-if-one-java-class-extends-another-at-runtime – Programmer Jun 27 '14 at 04:42
-