There is no main manifest attribute, in the bank
I am trying to run a jar generated by the maven shade plugin. I am setting up the main class like this:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>org.comany.MainClass</Main-Class>
<Build-Number>123</Build-Number>
</manifestEntries>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
...
But when I try to run the jar using java -jar app.jar it gives the following error:
"no main manifest attribute, in app.jar"
EDIT: I checked the contents of the jar with the jar tf app.jar and I can see the MANIFEST.MF file. BUt has no entry for the main class. How can I make sure the manifest file in the jar has this entry separately to add to the shadow plugin config?
+3
source to share
2 answers
The Maven shade plugin takes the JAR generated by the jar plugin and adds dependencies to it. Since it seems that the transforms in the shadow plugin are not working as expected, you just need to set up the config for the jar-plugin like this:
<build>
...
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.mypackage.MyClass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
<plugin>
[Your shade plugin definition without the transformers here]
</plugin>
</build>
+3
source to share