JMH no main manifest attribute
Asked Answered
A

1

8

I've just created a Maven project using this command:

$ mvn archetype:generate \
      -DinteractiveMode=false \
      -DarchetypeGroupId=org.openjdk.jmh \
      -DarchetypeArtifactId=jmh-java-benchmark-archetype \
      -DgroupId=org.sample \
      -DartifactId=test \
      -Dversion=1.0

Then I do a mvn clean install followed by java -jar test-1.0.jar

The program gives me this message

no main manifest attribute, in target/test-1.0.jar 

I've looked in the manifest and there's no Main-Class attribute.

This should have generated it:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.2</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <finalName>${uberjar.name}</finalName>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>org.openjdk.jmh.Main</mainClass>
                            </transformer>
                        </transformers>
                        <filters>
                            <filter>
                                <!--
                                    Shading signed JARs will fail without this.
                                    https://mcmap.net/q/45819/-quot-invalid-signature-file-quot-when-attempting-to-run-a-jar
                                -->
                                <artifact>*:*</artifact>
                                <excludes>
                                    <exclude>META-INF/*.SF</exclude>
                                    <exclude>META-INF/*.DSA</exclude>
                                    <exclude>META-INF/*.RSA</exclude>
                                </excludes>
                            </filter>
                        </filters>
                    </configuration>
                </execution>
            </executions>
        </plugin>
Awad answered 5/2, 2015 at 12:9 Comment(2)
Try with mvn clean package and generally, do not install because that puts the artifiact into your Maven cache.Alwitt
Using package has the same result (the instructions on the JMH site openjdk.java.net/projects/code-tools/jmh are to use install).Awad
A
10

The final output of the JMH Maven build is benchmarks.jar (the "uberjar") and the JAR you are running is just an intermediate result. So use

java -jar target/benchmarks.jar
Alwitt answered 5/2, 2015 at 12:22 Comment(1)
I've written up in this blog post hope this will help rationaljava.com/2015/02/…Awad

© 2022 - 2024 — McMap. All rights reserved.