Adarsh
Adarsh

Reputation: 227

How to load a .java file from a specified path and retrieve the declared methods in it?

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

Answers (1)

Jigar Joshi
Jigar Joshi

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

Related Questions