no main manifest attribute, in jar
I am trying to run a jar created by the maven shade plugin. I am configuring the main class the following way:
<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 running 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 using jar tf app.jar and I see a MANIFEST.MF file. BUt it does not have the entry for main class. How do I make sure the manifest file in jar has this entry apart for adding it in the shade plugin configuration?
Maven's shade plugin uses the JAR generated by the jar plugin and adds dependencies on it. Since it seems like the transforms on the shade plugin do not work properly, you just need to set the configuration for the jar-plugin like so:
<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>
不要忘记添加阴影作为目标:
mvn clean package shade:shade
上一篇: 运行使用Gradle构建的JAR文件时'没有主清单属性'
下一篇: 没有主要的清单属性,在jar中