'how to know which class / package/ methods used by given jar file?

I have a jar file. I want to know which external classes and methods are used by classes inside JAR file. Can anyone suggest me any tool?

For example - if below two classes are packaged into Myjar.jar

import java.util.Vector;
class MyJarClass{

    public static void main(String args[]){
        Vector v = new Vector();
        AnotherClass another = new AnotherClass();

        v.addElement("one");
        another.doSomething();

    }
}

class AnotherClass{

    void doSomething(){
    }
}

When I supply that JAR to a tool - the tool should show java.util.Vector and Vector.adElements() are from external source (not present in MyJar.jar)

Forgot to mention, i don't have access to sourcecode.



Solution 1:[1]

You might want to look at BCEL, which will allow you to parse the class files and find out what they use. I expect it'll be a certain amount of effort though.

Solution 2:[2]

Check untangle

It's a small cli utility that searches usages of class or packages inside jars or directories containing classes.

Disclaimer: I'm the author of untangle

Solution 3:[3]

Check JDepend

The graphical user interface displays the afferent and efferent couplings of each analyzed Java package, presented in the familiar Java Swing tree structure.

Solution 4:[4]

JavaDepend could help you for such needs, you can for any code elements get all elements used, it can be jar, namespace, class or method.

CQL an SQL like to query code base gives you more flexibility to request any info about your code.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jon Skeet
Solution 2 Enrico Sasdelli
Solution 3 stacker
Solution 4 James from CppDepend Team