maven关于打包的那些插件
在工作中使用maven创建java工程,管理jar包依赖,方便快捷。根据需要,需要把工程打包成各种需要的形式,这些打包插件就用到了。 现将各种打包用到的插件总结到这里,你可以参考官方文档,修改或者增加适合你的参数。 第一个:打源码包 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>2.1</version> <configuration> <attach>true</attach> </configuration> <executions> <execution> <phase>compile</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> 第二个:打全量包 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>1.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>com.zhaoyanblog.Launcher</mainClass> </transformer> <!--防止spring多个包同名配置文件覆盖--> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/spring.handlers</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/spring.schemas</resource> </transformer </transformers> </configuration> </execution> </executions> </plugin> 第三个:copy依赖jar包 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <includeScope>runtime</includeScope> <outputDirectory>target/lib/</outputDirectory> </configuration> </execution> </executions> </plugin> 第四个:指定main方法,修改manifest文件 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.3.2</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib</classpathPrefix> <mainClass>com.zhaoyanblog.Launcher</mainClass> </manifest> <manifestEntries> <Class-Path>conf/</Class-Path> </manifestEntries> </archive> <finalName>tools-${project.version}</finalName> </configuration> </plugin> 第五个:打压缩包。 ...