views:

23338

answers:

10

Does anyone know of a free decompiler that can decompile an entire Jar file instead of a single class? I have a problem with sub classes like name$1.class name$2.class name.class

+2  A: 

You extract it and then use jad against the dir.

alex
+22  A: 
VonC
A: 

A jar file is just a zip file with jar extension. You should be able to unzip(winzip) a jar just like a zip file.

Cadoo
+7  A: 

If you happen to have both a bash shell and jad:

JAR=(your jar file name)
unzip -d $JAR.tmp $JAR
pushd $JAR.tmp
for f in `find . -name '*.class'`; do
    jad -d $(dirname $f) -s java -lnc $f
done
popd

I might be a tiny, tiny bit off with that, but it should work more or less as advertised. You should end up with $JAR.tmp containing your decompiled files.

Chris R
A: 

If you use Eclipse then consider jadclipse - http://jadclipse.sourceforge.net/wiki/index.php/Main_Page - which runs jad on any class without a source file and display it.

Works very well.

If you need to debug on the classfile the preferences allow for source code alignment to the line numbers in the class file.

Thorbjørn Ravn Andersen
+8  A: 

First of all, it's worth remembering that all Java archive files (.jar/.war/etc...) are all basically just fancy.zip files, with a few added manifests and metadata.

Second, to tackle this problem I personally use several tools which handle this problem on all levels:

  • Jad + Jadclipse while working in IDE for decompiling .class files
  • WinRAR, my favorite compression tool natively supports Java archives (again, see first paragraph).
  • Beyond Compare, my favorite diff tool, when configured correctly can do on-the-fly comparisons between any archive file, including jars. Well worth a try.

The advantage of all the aforementioned, is that I do not need to hold any other external tool which clutters my work environment. Everything I will ever need from one of those files can be handled inside my IDE or diffed with other files natively.

Yuval A
lolz i keep unzipping chrome and firefox extensions and i forgot that .jar are just zips too :)
Carter Cole
A: 

I think the best way is to use the script. Decompiler's Archiver tool is great, it can create .java files from all of the classes in jar saving infrastructure, but it copies classes as well, so it isn't good if you wanna keep src and bin separate, because you'll have to delete all the .class files manually. Again, in archiver, deletion part can be done quite fast, if you have smaller jars - but for jars with hundreds of classes you'll end up with nightmares after the work:)

jhruby
A: 

Take a look at DJ Java Decompiler Archiver tool.

A: 

Is there a way to 'jad' a class without needing extract it from the jar file!? using pipe!?

Fabio Pupo
A: 

Something like:

jar -xf foo.jar && find . -iname "*.class" | xargs /opt/local/bin/jad -r

maybe?

cybertoast