Search code examples
javafile-read

Read outside .Java file and extract the method details into Java code


I need to read a java project files from outside of that project. So Java Reflection cannot be used. Is there any mechanism or specific API to read a .java files of a project and extract the method signature details into a java code. Maybe a text search API ?


Solution

  • You could still read it by providing the path to class file directory. And then you need to provide the exact package to the class file

    File file = new File("Absolute_path\\target\\classes\\");
        URL urlList[] = {file.toURL()};
        URLClassLoader loader = new URLClassLoader(urlList, Thread.currentThread().getContextClassLoader());
        Class c = (Class) Class.forName("com.java.dto.BaseDTO", true, loader);
    

    Thanks JTeam