Win a copy of Fixing your Scrum this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

How to read class files from jar file

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Marshal
Posts: 22386
121
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out the java.util.jar package.
 
Rancher
Posts: 43026
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43026
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's what decompilers like JODE and jad do.
 
Bartender
Posts: 2658
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are some copyright conditions to be checked when decompiling.
 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2658
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43026
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
I'm gonna teach you a lesson! Start by looking at this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic