1、以前面的HelloWorld项目为例,在pom.xml中添加如下代码,指定插件

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.lfy.main.mavenTest.App</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

2、运行maven clean、maven build选择package

Maven-maven插件(1)添加主类信息到MANIFEST.MF-LMLPHP

3、打开target包下的mavenTest-0.0.1-SNAPSHOT.jar的MANIFEST.MF文件,即可看到其中添加了Main-Class: com.lfy.main.mavenTest.App

Maven-maven插件(1)添加主类信息到MANIFEST.MF-LMLPHP

4、命令行运行独立可执行jar包

Maven-maven插件(1)添加主类信息到MANIFEST.MF-LMLPHP

05-28 09:21