###一、將工程打成jar包(不是可執行的jar包) 普通的maven java工程能夠經過pom文件的配置將工程打成jar包,可是該jar包沒法執行(經過java -jar xxx.jar此方式),由於jar包下的MANIFEST.MF文件中沒有MainClass信息。html
###二、將工程打成可執行的jar包 這裏使用maven-shade-plugin插件來打包,關於maven-shade-plugin和maven-assembly-plugin的差異,在這很少作說明,有興趣的能夠參考一下連接。java
http://chenzhou123520.iteye.com/blog/1706242spring
http://blog.csdn.net/defonds/article/details/43233131apache
最後直接放上maven-shade-plugin插件的配置:maven
<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>
###三、maven-shade-plugin官方文檔 參考maven官方文檔:ui
http://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html#.net
http://maven.apache.org/plugins/maven-shade-plugin/shade-mojo.html插件