本文主要是介绍maven 分离式打包,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
pom中插件配置:
<!-- Maven Jar 插件配置 -->
<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><configuration><archive><!-- 将类路径添加到 MANIFEST.MF 文件中 --><manifest><addClasspath>true</addClasspath><!-- 指定类路径前缀 --><classpathPrefix>lib/</classpathPrefix><!-- 指定程序的主类 --><mainClass>io.metersphere.Application</mainClass></manifest><!-- 在 MANIFEST.MF 中添加自定义条目 --><manifestEntries><!-- 添加资源文件的路径,这个必须要配置好,不然程序运行时候找不到资源文件的位置 --><Class-Path>conf/</Class-Path></manifestEntries></archive><!-- 包含的文件规则 --><includes><!-- 包含 io 包下的所有文件 --><include>io/**</include><!-- 包含 META-INF 目录下的所有文件 --><include>META-INF/**</include></includes></configuration>
</plugin><!-- Maven Assembly 插件配置 -->
<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-assembly-plugin</artifactId><executions><execution><id>bin</id><phase>package</phase><goals><goal>single</goal></goals><configuration><!-- 指定装配描述符文件 --><descriptors><descriptor>../assemblies/bin.xml</descriptor></descriptors></configuration></execution></executions>
</plugin>
具体设置装配文件:
<assemblyxmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"><!-- id 标识符,添加到生成文件名称的后缀符。如果指定 id 的话(这里指定的是项目的版本),目标文件则是 ${artifactId}-${id}.jar。【如terminal-dispatch-5.0.0.0.jar】 --><id>bin</id><!-- 指定打包格式。maven-assembly-plugin插件支持的打包格式有zip、tar、tar.gz (or tgz)、tar.bz2 (or tbz2)、jar、dir、war,可以同时指定多个打包格式 --><formats><format>tar.gz</format></formats><!-- 指定打的包是否包含打包层目录(比如finalName是terminal-dispatch,当值为true,所有文件被放在包内的terminal-dispatch目录下,否则直接放在包的根目录下)--><includeBaseDirectory>false</includeBaseDirectory><baseDirectory>devops-${project.version}</baseDirectory><dependencySets><dependencySet><!--不使用项目的artifact,第三方jar不要解压,打包进zip文件的lib目录--><useProjectArtifact>false</useProjectArtifact><outputDirectory>lib</outputDirectory><unpack>false</unpack></dependencySet></dependencySets><!-- 用来处理文件集合将其按照指定的方式输出--><fileSets combine.children="append"><fileSet><directory>src/main/resources/bin</directory><outputDirectory>bin</outputDirectory><fileMode>0755</fileMode></fileSet><fileSet><directory>../../</directory><outputDirectory>conf</outputDirectory><fileMode>0755</fileMode><includes><include>Dockerfile</include><include>Jenkinsfile</include><include>LICENSE</include><include>lombok.config</include><include>mvnw</include><include>mvnw.cmd</include><include>OWNERS</include></includes></fileSet><fileSet><directory>src/main/resources</directory><outputDirectory>conf</outputDirectory><fileMode>0755</fileMode></fileSet><fileSet><directory>../framework/sdk/src/main/resources</directory><outputDirectory>conf</outputDirectory><fileMode>0755</fileMode></fileSet><fileSet><directory>../services/api-test/src/main/resources</directory><outputDirectory>conf</outputDirectory><fileMode>0755</fileMode></fileSet><fileSet><directory>../services/bug-management/src/main/resources</directory><outputDirectory>conf</outputDirectory><fileMode>0755</fileMode></fileSet><fileSet><directory>../services/case-management/src/main/resources</directory><outputDirectory>conf</outputDirectory><fileMode>0755</fileMode></fileSet><fileSet><directory>../services/load-test/src/main/resources</directory><outputDirectory>conf</outputDirectory><fileMode>0755</fileMode></fileSet><fileSet><directory>../services/project-management/src/main/resources</directory><outputDirectory>conf</outputDirectory><fileMode>0755</fileMode></fileSet><fileSet><directory>../services/system-setting/src/main/resources</directory><outputDirectory>conf</outputDirectory><fileMode>0755</fileMode></fileSet><fileSet><directory>../services/test-plan/src/main/resources</directory><outputDirectory>conf</outputDirectory><fileMode>0755</fileMode></fileSet><fileSet><directory>../services/ui-test/src/main/resources</directory><outputDirectory>conf</outputDirectory><fileMode>0755</fileMode></fileSet><fileSet><directory>../../</directory><outputDirectory>doc</outputDirectory><fileMode>0755</fileMode><includes><include>*.md</include></includes></fileSet><fileSet><directory>../framework/domain/src/main/resources</directory><outputDirectory>script</outputDirectory><fileMode>0755</fileMode></fileSet><fileSet><directory>src/main/resources</directory><outputDirectory>logs</outputDirectory><excludes><exclude>**/*</exclude></excludes><fileMode>0755</fileMode></fileSet><fileSet><directory>src/main/resources</directory><outputDirectory>plugins</outputDirectory><excludes><exclude>**/*</exclude></excludes><fileMode>0755</fileMode></fileSet></fileSets><files><file><source>target/app-${revision}.jar</source><!-- 可以是相对路径或绝对路径,相对路径是相对与项目的根目录。--><outputDirectory>./</outputDirectory> <!-- 输出目录--><fileMode>0644</fileMode> <!--unix文件权限--></file></files></assembly>
这篇关于maven 分离式打包的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!