Search code examples
javaclassloaderdecompiling

Procyon: decompiling specific classes of jar


I'm trying to decompile specific classes from a jar file using the com.strobel.decompiler.Decompiler decompiler from the Procyon library.

This is my current approach:

// jar file containing foo.class and bar.class
JarFile myJar = new JarFile("my.jar");
// creating decompiler settings
DecompilerSettings settings = new DecompilerSettings();
// set type loader to jar file
settings.setTypeLoader(new JarTypeLoader(myJar));

StringWriter foo = new StringWriter();
Decompiler.decompile("com.myjar.foo", new PlainTextOutput(foo), settings);
System.out.print(foo.toString());

But this does only print: !!! ERROR: Failed to load class com.myjar.foo.

I'm pretty sure I missed something for class loading the classes from my.jar. (Thought this would be done by setting the type loader).

The actual question: how do I decompile a specific class from a jar file with the procyon decompiler ? (what i've done wrong in my approach ?)

Greets, NopMind.


Solution

  • The answer is simple: class namespaces are not prefixed with . then with / instead.

    So just replacing Decompiler.decompile("com/myjar/foo", ...) works fine. Sorry