Using Manual command

jar cfe test-1.0-fixed.jar com.test.Main -C target/classes .

Legends:

Sample:

java -jar test-1.0-fixed.jar

Using Maven POM

Add this to your pom.xml:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
      <version>3.2.2</version>
      <configuration>
        <archive>
          <manifest>
            <mainClass>com.test.Main</mainClass>
          </manifest>
        </archive>
      </configuration>
    </plugin>
  </plugins>
</build>

✅ Confirm the Manifest

After rebuilding, check it:

unzip -p target/test-1.0.jar META-INF/MANIFEST.MF

You should see:

Main-Class: com.test.Main