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.
                                    http://stackoverflow.com/questions/999489/invalid-signature-file-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>
Dan
  • 9,681
  • 14
  • 55
  • 70
  • Try with `mvn clean package` and generally, do not `install` because that puts the artifiact into your Maven cache. – Marko Topolnik Feb 05 '15 at 12:13
  • Using package has the same result (the instructions on the JMH site http://openjdk.java.net/projects/code-tools/jmh/ are to use install). – Dan Feb 05 '15 at 12:18

1 Answers1

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
Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436
  • I've written up in this blog post hope this will help http://www.rationaljava.com/2015/02/jmh-how-to-setup-and-run-jmh-benchmark.html – Dan Feb 06 '15 at 10:40