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

JAR包中生成的ENUM类无法访问,求排查可能原因

Why Your Generated Enum Class Isn't Visible in Another Module

It’s frustrating when most classes in your JAR work cross-module but one enum doesn’t—let’s walk through the most probable causes and fixes:

  • Package-private access level
    The #1 culprit here is usually missing the public modifier on your enum. If it’s declared as enum YourEnum (instead of public enum YourEnum), it’s package-private by default. That means it can only be accessed within its own package, so other modules (which are in different packages) can’t see it. Check the generated enum’s source code to confirm the access modifier.

  • Missing enum .class file in the JAR
    Your jar tf output shows the directory structure, but it doesn’t explicitly list the enum’s compiled .class file. Run jar tf your-project.jar | grep YourEnum (replace with your actual enum name) to verify if the file exists. If it’s missing, your build process might not be compiling the generated enum or including it in the JAR. Check your build script (Maven, Gradle, etc.) to ensure the generated Java file is part of the compilation and packaging steps.

  • Java Module System (Java 9+) restrictions
    If you’re using modules (with module-info.java), you need to explicitly export the package containing the enum from its module. Add exports com.processing.commonutils.enumGenerator; to the module-info.java of the module where the enum lives. Also, make sure the dependent module has a requires your-module-name; declaration to pull in the module with the enum. Without these, even public enums are blocked between modules.

  • Classloader mismatch
    This is less common, but possible in complex setups like application servers. If the module containing the JAR and the dependent module are loaded by different classloaders, the enum class might not be visible across them. To debug, print the classloader for a working class and compare it with the enum’s (if you can reference it) using WorkingClass.class.getClassLoader() and YourEnum.class.getClassLoader().

  • Typos or package name discrepancies
    Double-check that the package name you’re using to import the enum matches exactly what’s in the JAR. A tiny typo (like lowercase enumgenerator instead of enumGenerator) will cause the JVM to fail locating the class, even if it’s present in the JAR.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 07:36:55