Maven打包的时候,是不是经常会出现 “没有主清单属性” 的报错?以下的配置,放在 pom.xml 最后的 < build > 中,就能自定义main函数所在的类,然后打包了:
<build>
<finalName>JarPackageFileName</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<!--这里写你的main函数所在的类的路径名,也就是Class.forName的那个字符串-->
<mainClass>com.hello.MainClass</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>