Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JMH no main manifest attribute

Tags:

java

jmh

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>
like image 294
Dan Avatar asked Feb 05 '15 12:02

Dan


1 Answers

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
like image 55
Marko Topolnik Avatar answered Oct 18 '22 15:10

Marko Topolnik