I am working on project of java that needs to decompile .class file to source code, I've found many ways such as such as JAD decompiler and 'javap -p' method... , but I think these methods are cannot be done programatically (please tell if can), Is there any way to done this programatically, It would be appreciated if you show me any Libraries.
Asked
Active
Viewed 5,539 times
7
-
1how about https://code.google.com/p/back2code/source/checkout – Sachin Verma Feb 28 '14 at 05:13
-
@SachinVerma The link you have given is a little help full,but it doesn't reach me in to the answer, – droidev Feb 28 '14 at 05:50
-
1Thats why i didn't put it in answer – Sachin Verma Feb 28 '14 at 05:51
-
@SachinVerma thats fine, actually I am new to stackoverflow, I dont know the rules and regulations, any way thanks :) – droidev Feb 28 '14 at 05:55
1 Answers
6
Procyon is a Java decompiler written in Java, and it can be called directly from Java code. For example:
final PrintWriter writer = new PrintWriter(System.out);
try {
com.strobel.decompiler.Decompiler.decompile(
"W:\\Hello.class",
new com.strobel.decompiler.PlainTextOutput(writer)
);
}
finally {
writer.flush();
}
There is also a decompile()
overload that accepts a DecompilerSettings
instance, which you can use to toggle certain features and give the decompiler hints on how to resolve class dependencies. Feel free to contact me on BitBucket with any questions.

Mike Strobel
- 25,075
- 57
- 69
-
actually I need the .java file to be printed in console, what method I have to use for that, do you have any documentation for Proycon ? – droidev Mar 05 '14 at 05:47
-
1The example above will print the output to the console. If you want to print to some other source, just pass another kind of `Writer` when creating the `PlainTextOutput`. I don't have any documentation at the moment, but I can answer any questions you might have. – Mike Strobel Mar 05 '14 at 13:59
-
1Apologies for not testing my own answer. The problem seems to be that the writer's buffer is not being flushed automatically. – Mike Strobel Mar 10 '14 at 17:41