1

In my spring application i need to identify the methods in a java file which is saved in a temporary location(Files not in the current project)

eg: C:\Users\Guest\Desktop\File.java i need to get the all the methods in this file

is there a way to change the below code or any other methods

ClassName t = new ClassName();

        Class tClass = t.getClass();
        Method[] methods = tClass.getMethods();
        for (int i = 0; i < methods.length; i++) {
            System.out.println("public method: " + methods[i]);
        }
  • 3
    [Either compile the .java file](https://stackoverflow.com/questions/12019050/compile-a-java-file-with-a-java-program), and then you can use the reflection approach, or if all you really need is the method names, you should be able to derive a [regular expression to parse the file](https://stackoverflow.com/questions/68633/regex-that-will-match-a-java-method-declaration). – KevinO Mar 23 '19 at 22:12
  • As @KevinO says use the reflection !! take a look at this article [link](https://dzone.com/articles/how-to-compile-a-class-at-runtime-with-java-8-and) – Djamel Kr Mar 23 '19 at 22:39
  • Or use a language recognition tool such as [ANTLR 4](https://en.m.wikipedia.org/wiki/ANTLR). – Basil Bourque Mar 24 '19 at 00:03
  • Hi @KevinO I need all the parameters return types and exceptions too – Saneth Chandrasekara Mar 24 '19 at 08:39

0 Answers0