默认打包生成的jar是不能直接运行的,因为带有main方法的信息不会添加到mainifest中,需要借助maven-shade-plugin
-
<project>
-
...
-
<build>
-
<plugins>
-
<plugin>
-
<groupId>org.apache.maven.plugins</groupId>
-
<artifactId>maven-shade-plugin</artifactId>
-
<version>2.0</version>
-
<configuration>
-
<transformers>
-
<transformer implementation = "org.apache.maven.plugins.shade.resource.MainifestResourceTransformer">
-
<mainClass>com.xun.pf.sayHello.HelloWorld</mainClass>
-
</transformer>
-
</transformers>
-
</configuration>
-
<executions>
-
<execution>
-
<phase>package</phase>
-
<goals>
-
<goal>shade</goal>
-
</goals>
-
</execution>
-
</executions>
-
</plugin>
-
</plugins>
-
</build>
-
...
-
</project>
com.xun.pf.sayHello.HelloWorld为包含main方法的class就可以使用Java -jar xxx.jar执行了参考:徐晓斌
原文地址:https://blog.csdn.net/xun_2008/article/details/16832151