Obfuscate Class Names With Main Methods

I’m using ProGuard to obfuscate executable .jar files. When I decompile the code using Procyon the classes with main methods still have their original names. This is due to

-keepclasseswithmembers public class * {
    public static void main(java.lang.String[]);

in the default configuration.

If I remove this, ProGuard won’t process. Is there a way to obfuscate class names with main methods as well or is there a good reason against it?


If you obfuscate the classname with the main method, you can no longer call that class to run the jar.

In theory, you could modify the MANIFEST.MF in the jar to refer to the obfuscated classname, but I’m not sure the benefit of that, since it is pretty clear what you are calling at that point.

Further, you can never obfuscate the main(String[]) method name itself, or java can’t find and run your application at all. That’s a pretty good reason against it 🙂

If you want to obfuscate the rest of the class members, but keep the classname and main method itself, you can do that with

-keep public class mypackage.MyMain {
    public static void main(java.lang.String[]);

as per the first example in proguard manual.

Leave a Reply

Your email address will not be published. Required fields are marked *