Hi All, What I want to do is pretty simple. I have some java source files. I want to find the public methods in the Java files.
How do I achieve this? I do not want to parse the files and then go line by line and search for the public keyword.
I tried using reflection so that I could just query the .class file. Load it via Class.loadClass() and then get all the methods. However if the class references a file which is in another jar in the project then how do I get that information. If I try to query the class without having loaded the referenced class I get a ClassNotFoundException.
Hi, Yes the files do compile. The problem with using reflection as I have mentioned in my post is that the .class file expects any class referenced in the .class file to be also loaded before any methods are called on the loaded class.
for ex: I have a X.class file which is compiled from X.java. X.java contains references to Y.java. Now when we call Class.loadClass on X.class, if you want to do anything meaningful on the Class returned then you have to ensure that Y.class is also loaded else you will get a ClassNotFoundException.
SO -- Is there a different way to use reflection which will ensure that when I load Class X all of the classes that X references are also loaded?
This happens when you are using one precompiled jar file ( containing class files only) which depends upon another set of jar files. for example if we use hibernate.jar then we have to also use some other jar files ( like dom4j CGLIB etc..unless they are not already in your classpath ).
The mandatory thing that we have to reckon with is to go through the 'readme' file to know all the dependencies of the jar file in question and add all those jar libraries also in your project / classpath. Typically the jar file providor also provides the dependent jar files in another folder like lib / ext.
well if all this is a head ache, then you can load the Class file through the util.jar apis and then use the defineClass() method to bring in all the classes that X depends upon. but the procedure defined above would avoid you to phisically load all the classes through the defineClass etc.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com