• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to read class files from jar file

 
Gab Narwaria
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i want to read class files from jar file and then want to decompile all .class files into java files.
Is it possible using java APIs or through any other third party APIs?

Please help me about this i have not tried ever to read class file so its quite difficult to me to play with byte code (.class) file.

 
Rob Spoor
Sheriff
Pie
Posts: 20745
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the java.util.jar package.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might also want to check out one of the existing libraries for reading class files, like BCEL and jclasslib,
 
Gab Narwaria
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:Check out the java.util.jar package.



Thanks for reply.
I can read data from jar file using java.util.jar package, but from here onward how to convert class files into java files.
actully my jar files contains only class files and i want to scan class files to extract some matching code from class file.

There is some java code in java file and now i dont have java files, i have only .jar file and it contains all class files so i want to develop utility that could scan all class files and return my desired out put.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what decompilers like JODE and jad do.
 
Jan Cumps
Bartender
Posts: 2608
14
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are some copyright conditions to be checked when decompiling.
 
Mahesh Kedari
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
take a look at this. probably it'll be helpful to you. Also you can use google for searching De compiling tools.
But none of the tool can give you a 100% guarantee of generating a perfect source code.
 
Jan Cumps
Bartender
Posts: 2608
14
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(getting carried away a little bit)
Wow. Cool.

I checked it with this small program I made:


And this is what came out of the tool:


Quite similar. The only thing missing seems to be the generics info.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only thing missing seems to be the generics info.

None of the publicly available decompilers I've seen support the Java 5 class file extensions (like generics). That information is in the class file, it just seems that nobody bothered to update the decompilers. I hacked up a copy of JODE at one point in order to add that, and came to the conclusion that it is indeed possible if one were so inclined (at least for classes, instance fields and method parameters, not sure about local variables).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic