Karim Narsindani
Karim Narsindani

Reputation: 454

How to copy method from class file in java application

I am writing framework which required to store methods in database. The thing is I have written all the method in java file, now I have UI where user will select the method and when user click on save button, system needs to copy selected method from java file and save in database, the reason doing this is when running application system will call id which will be mapped with stored method in database and will execute that method to achieve goal. Is this possible? and how to copy method from java class file and store in db?

Is there any other suggestion or input will be more appreciated.

Thanks,

Upvotes: 0

Views: 124

Answers (1)

vipul mittal
vipul mittal

Reputation: 17401

Getting a source code for method would be difficult as the original code is not available to a running program.

Know more here

But you can do the following:

Using java reflection api(javaassist) you can add a method to existing class. And start from storing first definition of the method in DB fetch it and put it in a class. So you can, at any time, get it and display as well as change.

Upvotes: 1

Related Questions