Search code examples
javajardecompiling

Get all external source paths that a JAR uses


I have a problem with finding all the external libraries that a .jar file uses. My .jar file is very big, and manually decompiling it and going through every class, checking all the used paths is impossible. I wonder if there is a way or a tool that would go through a .jar file, and list all the external paths/links to classes that are not in the .jar file?

P.S: I'm not asking "what is the best tool to do so?", I just need to know how to get all the external paths a .jar file uses, without manually decompiling it.


Solution

  • Try this :

    1. Extract the jar contents
    2. Do a directory search for *.class piped to a text file.
    3. Filter out inner and anonymous classes. (Class files names with $)
    4. Write a small program that will simply loop through your list and load the class definition (Class.forName() should be enough)
    5. Run the jar with option -verbose:class piped to a text file
    6. Once your program is completed, you will have a full list of classes loaded from respective jars in the piped file
    7. Filter out rt.jar contents for a more cleaner list

    I'm not sure if -verbose:class works with obfustcated code, logically I think it should be fine.