You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Proguard混淆后HelloWorld示例程序无法运行问题咨询

Fixing "Main Method Not Found" After ProGuard Obfuscation

Hey there, let's work through this issue you're facing—obfuscating your JAR with ProGuard leads to a "main method not found" error, and even decompiling doesn't show the main method anymore. Here's what's happening and how to fix it:

Why This Happens

ProGuard's default behavior is to remove code it deems "unused" and obfuscate class/method names. Since it doesn't automatically recognize your main method as the application entry point, it might either rename it beyond recognition or strip it entirely during optimization.

Step-by-Step Fixes

Let's adjust your ProGuard configuration to preserve the necessary components:

  1. Explicitly keep the main method and its containing class
    Add these rules to your ProGuard config file—this tells ProGuard not to touch the main class or its main method:

    # Keep the HelloWorld class and its main method
    -keep class com.proguard.sample.HelloWorld {
        public static void main(java.lang.String[]);
    }
    

    If you want to keep the entire class's name and structure intact (to avoid messing with your JAR's MANIFEST.MF), you can simplify it to:

    -keep class com.proguard.sample.HelloWorld
    
  2. Verify your MANIFEST.MF (if applicable)
    If your original JAR has a MANIFEST.MF that specifies Main-Class: com.proguard.sample.HelloWorld, make sure the obfuscated JAR still includes this manifest, and that the class name hasn't been changed (the rule above ensures this).

  3. Check for over-aggressive optimizations
    If you've added -optimizations flags, ensure none of them are configured to remove entry-point methods. For most simple cases, sticking with the default optimization settings plus the keep rules above will work.

How to Test

  • Re-run ProGuard with the updated configuration to generate the obfuscated JAR
  • Execute the new JAR—you should see "Hello world" print as expected
  • Decompile the obfuscated class file again; the main method should now be present (either with its original name or preserved if you kept the class intact)

内容的提问来源于stack exchange,提问作者Pej

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 08:12:55