确定项目中有public static void main(String[] args)方法
在pom.xml中使用插件org.apache.maven.plugins.maven-shade-plugin,并在其配置中指明主类的位置,具体是在<mainClass>hello.HelloWorld</mainClass>处定义主类的位置。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>hello.HelloWorld</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>