Search code examples
javadecompiling

How can I find which java class reads a particular xml file?


I'm workin on a java application for which i don't have all the source codes. The application is based on spring framework, and at startup it parses lots of xml files from different directories. Then it makes an internal cache of the given xml content which I would like to disable and make changes in the class to read the xml content when it's needed and don't cache them. For this reason i have to find out which class opens my xml.

(If i can find it out, then i can ask for source code access, but till then i wont get access to it.)

What else i know about this class is it parses lots of xmls from different directories so the filename wont be hardcoded into the class.

I was thinking of to use a decompiler to reverse engineer the class files, but there are a lot, and the package hierarchy is too deep to do it one by one. Maybe there is a way to decompile whole jar files at once with an eclipse plugin or a command line tool, but i don't know how. Anyway maybe there is a much simpler solution.

Any ideas?


Solution

  • This sound like a job for debugger. In particular - conditional breakpoint.

    In eclipse this can be done like this:

    1. Set breakpoint in FileInputStream(File) (it's almost certain this class will be used to read the file).
    2. In breakpoint view, click on breakpoint -> "Breakpoint Properties...".
    3. Check "Conditional"
    4. Enter some expression which will detect the file you are interested in. For example: arg0.getPath().endsWith("test.xml").
    5. Start the program and wait until break point is hit.
    6. You will be able to get the callers from stack trace.