您的位置:首页 > 运维架构

DevOps进阶(八)maven三种打包插件

2018-12-05 09:52 489 查看
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sunhuaqiang1/article/details/84819635

maven三种打包插件

maven有多种可以打包的插件,如下:

plugin function 官网
maven-jar-plugin maven 默认打包插件,用来创建 project jar
maven-shade-plugin 用来打可执行包,executable(fat) jar http://maven.apache.org/plugins/maven-shade-plugin/examples/includes-excludes.html
maven-assembly-plugin 支持定制化打包方式,例如 apache 项目的打包方式 http://maven.apache.org/plugins/maven-assembly-plugin/usage.html

我们主要是要打zip包,也就是要使用maven-assembly-plugin插件。

maven-assembly-plugin pom配置

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<descriptors>
<descriptor>src/main/package.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase> <!--this is used for inheritance merges  绑定到这个生命周期-->
<goals>
<goal>single</goal> <!--执行一次-->
</goals>
</execution>
</executions>
</plugin>

指定打包文件 src/main/package.xml,在该配置文件内指定打包操作。

配置文件

<assembly xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/assembly-1.0.0.xsd">
<id>full</id>
<!--这个id会出现在zip包名称的后面,zip的完整名是:pom.xml中的artifactId-version-id.zip -->
<formats>
<!--支持的打包格式有zip、tar、tar.gz (or tgz)、tar.bz2 (or tbz2)、jar、dir、war-->
<format>zip</format>
</formats>

<dependencySets>
<!-- 用来定制工程依赖 jar 包的打包方式,依赖包的输出路径 -->
<dependencySet>
<outputDirectory>/libs</outputDirectory> <!--依赖jar包的输出目录-->
<useProjectArtifact>false</useProjectArtifact>

<includes> <!--指定把哪些依赖包放进去  -->
<!--如果不指定  则所有的依赖都会打入,但是有的时候  我们只需要打特定依赖的包-->

<include>net.sf.jsi:jsi</include>
<include>net.sf.trove4j:trove4j</include>

</includes>

</dependencySet>
</dependencySets>

<includeBaseDirectory>true</includeBaseDirectory>
<fileSets><!--这里指定需要包含的其他文件-->
<fileSet>
<!--管理一组文件的存放位置-->
<outputDirectory>/</outputDirectory> <!--放在哪-->
<directory>target</directory><
4000
;!--源目录-->
<includes>
<include>*.jar</include>  <!--代码的jar包-->
</includes>
</fileSet>

<fileSet>
<outputDirectory>/shell</outputDirectory>
<directory>src/main/resources/shell</directory>
<includes>
<include>*/*.sh</include>  <!--把shell脚本打进去-->
<include>*/*.conf</include>  <!--把conf文件打进去-->
</includes>
</fileSet>

</fileSets>
</assembly>

这个xml的配置属性及其说明参见:http://gitlab.tenddata.com/data-process/gp-etl/blob/spark2.3test/src/main/package.xml

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: