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

IntelliJ生成可执行API JAR时提示no main manifest attribute错误求助

Fixing "no main manifest attribute" in your API JAR

Hey there, let's work through this frustrating issue together. Since you mentioned you can see your main class in the Artifact wizard, we can skip the basics and focus on the often-overlooked details that cause this error even when the main class exists.

1. Double-check your IntelliJ Artifact Manifest configuration

Sometimes the manifest is either missing or not properly linked to your main class. Here's how to verify:

  • Open Project Structure (use Ctrl+Alt+Shift+S on Windows/Linux, Cmd+; on Mac)
  • Navigate to Artifacts and select your api.jar artifact
  • Look for a META-INF/Manifest.mf entry under the artifact. If it's missing:
    • Right-click the artifact > Add > Empty Manifest
    • Choose the path to store the manifest (typically src/main/resources/META-INF/ so it's included in your source files)
  • Once the manifest exists, select it and in the right-hand pane, click the ... next to Main Class
  • Pick your main class from the list, save the configuration, and rebuild the artifact

2. Ensure your build tool explicitly sets the main class

If you're using Maven or Gradle, relying solely on IntelliJ's artifact wizard might not be enough—your build script needs to define the main class too:

For Maven users

Add or update the maven-jar-plugin in your pom.xml:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.3.0</version>
            <configuration>
                <archive>
                    <manifest>
                        <!-- Replace with your actual main class path -->
                        <mainClass>com.yourcompany.api.YourMainClass</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

Then run mvn clean package to rebuild the JAR.

For Gradle users

Add this block to your build.gradle (or build.gradle.kts for Kotlin):

jar {
    manifest {
        attributes 'Main-Class': 'com.yourcompany.api.YourMainClass' // Replace with your main class
    }
}

Rebuild with ./gradlew clean build (or gradlew.bat clean build on Windows).

3. Verify the manifest inside the JAR

Let's confirm the manifest was actually included correctly:

  • Unzip your api.jar (use unzip api.jar in the terminal, or a GUI tool like WinZip)
  • Navigate to the META-INF folder and open Manifest.mf
  • Look for a line that looks like:

    Main-Class: com.yourcompany.api.YourMainClass

  • Make sure there's one space after the colon, and this line isn't wrapped or missing. If it's not present, your build process isn't generating the manifest properly—go back to step 2 or 1.

4. Clear IntelliJ's build cache

Sometimes stale cache files mess up the build process:

  • Go to File > Invalidate Caches...
  • Select Invalidate and Restart
  • Once IntelliJ reopens, rebuild your artifact from scratch

Give these steps a try—usually one of them fixes the issue when the main class is already present but the manifest isn't set up right.

内容的提问来源于stack exchange,提问作者James Jordan Taylor

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 03:57:54