Reputation: 227
I want to load a .java file from a specified path and retrieve the methods declared in it. Please find below the sample.
There is a java file in a location D:/Sample/Test.java
I have declared two methods in it test1()
and test2()
.`
I know that by using classobj.getClass().getDeclaredMethods()
I can retrieve the methods declared in it. But my problem is in loading the .java
file.
Could anyone please provide me a solution for this..
Regards, Adarsh K S
Upvotes: 1
Views: 226
Reputation: 240948
First you need to compile that java class
then you can use URLClassLoader
to load class from specific location and then you can invoke getDeclaredMethods()
Upvotes: 3