###1、将工程打成jar包(不是可执行的jar包) 普通的maven java工程可以通过pom文件的配置将工程打成jar包,但是该jar包无法执行(通过java -jar xxx.jar此方式),因为jar包下的MANIFEST.MF文件中没有MainClass信息。
###2、将工程打成可执行的jar包 这里使用maven-shade-plugin插件来打包,关于maven-shade-plugin和maven-assembly-plugin的差别,在这不多做说明,有兴趣的可以参考一下链接。
http://chenzhou123520.iteye.com/blog/1706242
http://blog.csdn.net/defonds/article/details/43233131
最后直接放上maven-shade-plugin插件的配置:
<build>
<finalName>mqConsumer</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.yunhetong.mq.App</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
###3、maven-shade-plugin官方文档 参考maven官方文档:
http://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html#
http://maven.apache.org/plugins/maven-shade-plugin/shade-mojo.html
来源:oschina
链接:https://my.oschina.net/u/2401585/blog/733457