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

如何让IntelliJ识别Manifest中的Automatic-Module-Name?

Fixing IntelliJ's Unrecognition of JARs with Automatic-Module-Name

Hey, I've run into exactly this issue before—everything compiles and runs perfectly fine, but IntelliJ stubbornly flags the requires directive in module-info.java and related import statements as errors. Total headache, right? Here are some tried-and-true solutions that worked for me:

1. Force a Full Project Resync & Cache Clear

More often than not, this is just an IDE cache or sync glitch. Try these steps:

  • If you're using Maven/Gradle, click the sync button in the top-right corner of the IDE (the circular arrows icon);
  • Or use the menu options: File → Sync Project with Gradle Files (for Gradle) / File → Sync Project with Maven Projects (for Maven);
  • For stubborn cases, go to File → Invalidate Caches..., check the box for "Clear file system cache and local history", then restart IntelliJ. This wipes out all wonky cached data that might be causing the misbehavior.

2. Verify the JAR is on the Modulepath (Not Classpath)

Automatic modules only work when the JAR is placed on the modulepath, not the traditional classpath. Double-check this:

  • Open File → Project Structure → Modules;
  • Select your main module, switch to the Dependencies tab;
  • Locate the problematic JAR—its scope should be set to Modulepath. If it's on Classpath, use the dropdown to switch it, then apply and save changes.

3. Manually Associate the Module (For Non-Build-Tool Projects)

If you're adding the JAR manually (no Maven/Gradle), make sure IntelliJ correctly maps it to the automatic module name:

  • Go to File → Project Structure → Libraries;
  • Right-click the JAR and select Add to Modules;
  • In the popup, ensure your main module is selected. IntelliJ should auto-detect the Automatic-Module-Name from the manifest, but if it doesn't, double-check that the requires statement in your module-info.java exactly matches the name in the manifest (module names are case-sensitive!).

4. Validate Build Tool Configurations (Maven/Gradle)

If you're using a build tool, confirm your setup is correct:

  • Maven: No special config is needed—Maven automatically recognizes Automatic-Module-Name from the JAR's manifest. Try right-clicking your project → Maven → Reload Project to refresh dependencies.
  • Gradle: Ensure you're using implementation or api for the dependency, and that the Java plugin is enabled (Gradle 6+ supports modules by default). Run gradle clean build from the terminal, then sync the project with IntelliJ.

5. Double-Check Module Name Spelling & Case

Last but not least, verify there's no typo:

  • Open the JAR's META-INF/MANIFEST.MF and copy the exact value of Automatic-Module-Name;
  • Compare it against the requires statement in your module-info.java—even a single uppercase/lowercase mismatch will cause IntelliJ to throw a fit.

Most of the time, either the cache clear or modulepath fix will resolve the issue. I fixed mine with the invalidate cache + resync combo, so start there!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 08:37:56