maven使用组装如何实现打包

  介绍

这篇文章运用简单易懂的例子给大家介绍maven使用组装如何实现打包,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

要使用装配进项编译打包,首先主要在pom中的构建中添加插件信息,具体如图下所示:

& lt; build>   & lt; finalName> $ {project.artifactId} & lt;/finalName>   & lt; sourceDirectory> src/main/java   & lt; resources>   & lt; resource>   & lt; directory> src/main/resources   & lt; filtering> true   & lt; includes>   & lt; include> * */* .xml   & lt; include> * */* .properties   & lt;/includes>   & lt;/resource>   & lt; resource>   & lt; directory> $ {profile.dir} & lt;/directory>   & lt; filtering> true   & lt;/resource>   & lt;/resources>      & lt; plugins>   & lt; !——编译器插件参数设置,指定编码——比;   & lt; plugin>   & lt; groupId> org.apache.maven.plugins   & lt; artifactId> maven-compiler-plugin   & lt; version> 3.1 & lt;/version>   & lt; configuration>   & lt; source> 1.8 & lt;/source>   & lt; target> 1.8 & lt;/target>   & lt; encoding> utf-8   & lt;/configuration>   & lt;/plugin>      & lt; !——这个插件是关键——比;   & lt; plugin>   & lt; groupId> org.apache.maven.plugins   & lt; artifactId> maven-assembly-plugin   & lt; configuration>   & lt; !——这个是组装所在位置——比;   & lt; descriptor> src/main/组装/assembly.xml   & lt;/configuration>   & lt; executions>   & lt; execution>   & lt; id> make-assembly   & lt; phase> package   & lt; goals>   & lt; goal> single   & lt;/goals>   & lt;/execution>   & lt;/executions>   & lt;/plugin>   & lt;/plugins>   & lt;/build>

创建组装文件夹和组装。xml文件,这个样子创建主要是规范只

在pom中已经介绍组装。xml位置。

& lt; !——这个是组装所在位置——比;   & lt; descriptor> src/main/组装/assembly.xml   

创建组装。xml文件后添加如下内容:

& lt; assembly>   & lt; formats>   & lt; !tar.gz——支持邮政,焦油,焦油。bz2,获取jar、意外死亡、战争等——比;   & lt; format> tar.gz   & lt; format> zip   & lt; format> dir   & lt;/formats>   & lt; includeBaseDirectory> false   & lt; fileSets>   & lt; fileSet>   & lt; directory> src/main/resources   & lt; outputDirectory> conf   & lt; fileMode> 0644 & lt;/fileMode>   & lt;/fileSet>   & lt; fileSet>   & lt; directory> $ {profile.dir} & lt;/directory>   & lt; outputDirectory> conf   & lt; !——表示的是包含下面格式的资源文件——比;   & lt; includes>   & lt; include> * .xml   & lt; include> * .properties   & lt; include> * */* .xml   & lt; include> * */* .properties   & lt;/includes>   & lt; fileMode> 0644 & lt;/fileMode>   & lt;/fileSet>   & lt; fileSet>   & lt; directory> src/main/组装/bin   & lt; outputDirectory> bin   & lt; fileMode> 0755 & lt;/fileMode>   & lt;/fileSet>   & lt;/fileSets>   & lt; dependencySets>   & lt; dependencySet>   & lt; outputDirectory> lib   & lt;/dependencySet>   & lt;/dependencySets>   & lt;/assembly>   

fileMode官方解释:

类似于UNIX权限,包括设置文件的文件模式。这是一个八进制值。格式:(用户)(集团)(其他),其中每个组件是一个阅读=4,写=2,执行=1。例如,值0644转化为用户读写,集团和其它

上述的三个文件集分别是将资源下的资源打包到配置目录下,将装配下的本启动相关脚本打包到本目录下,将maven项目依赖的所有jar包,打包到lib中只

具体结构如下图所示:

 maven使用组装如何实现打包

参考地址:http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html

zip.xml文件配置如下

& lt;组装   xmlns=癶ttp://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"   xmlns: xsi=癶ttp://www.w3.org/2001/XMLSchema-instance"   ,xsi: schemaLocation=癶ttp://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"的在;   & lt; id> release

maven使用组装如何实现打包