Decompile java class file

advertisements

Is it possible to decompile a java .class file within another program ? I'm aware of tools like CAVAJ and DJ Java Decompiler. Why ? : I'm modifying a class file within the program and dumping it into the same. I want to then parse the source file of the modified class file. Thanks in advance.


Here is a possible answer (this is what I use for compiling source files)

private int runProcess(String command) throws Exception
{
    Process pro = Runtime.getRuntime().exec(command);
    System.out.println(command);
    printLines("", pro.getInputStream());
    printLines("",pro.getErrorStream());
    pro.waitFor();
    return(pro.exitValue());
}

Then you can use something like:

int exitValue = runProcess(your command here);

I guess JD-GUI will not work; you need a command line java decompiler.

These links might help:
Batch decompiling of Java files with JD-GUI
http://en.wikipedia.org/wiki/JAD_%28JAva_Decompiler%29
http://viralpatel.net/blogs/decompile-class-file-java-decompiler-class-java-class/

The last link has a download link to JAD, a command line tool for windows computers.

Depending on the OS the command might vary but it might just be "jad classname.class" if you move jad to your cmd class path. I have mac os x so I am not sure where this is located.

I hope this helps!