How do I print the class structures in a jar file using the javap tool?

[亡魂溺海] 提交于 2019-11-30 05:04:57
#!/bin/bash
# Set the JAR name
jar=<JAR NAME>
# Loop through the classes (everything ending in .class)
for class in $(jar -tf $jar | grep '.class'); do 
    # Replace /'s with .'s
    class=${class//\//.};
    # javap
    javap -classpath $jar ${class//.class/}; 
done

Even easier would be

JAR=<path to jarfile> \
javap -classpath $JAR $(jar -tf $JAR | grep "class$" | sed s/\.class$//)

First unzip the jar file, this will yield a series of directories for each package, then apply the javap command per directory.

So for example with tomcat you can unzip the catalina-balancer.jar file in webapps\balancer and then use

javap -classpath org\apache\webapp\balancer Rule

which gives

Compiled from "Rule.java"
interface org.apache.webapp.balancer.Rule{
    public abstract boolean matches(javax.servlet.http.HttpServletRequest);
    public abstract java.lang.String getRedirectUrl();
}

If you need to do this for all the class files in a package you will need to write a script or program to walk the classpath and strip the .class from the filenames and pass it to javap.

(It would be fairly easy to write in perl/bash/java).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!