1、在项目的pom文件中引入
<profiles> <profile> <id>release</id> <activation> <property> <name>env</name> <value>release</value> </property> </activation> <build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <executions> <execution> <id>linux64</id> <phase>package</phase> <goals> <goal>single</goal> </goals> <configuration> <descriptors> <descriptor>src/main/assembly/release-linux64.xml</descriptor> </descriptors> <finalName>${project.artifactId}</finalName> <outputDirectory>${project.parent.build.directory}</outputDirectory> </configuration> </execution> <execution> <id>linux32</id> <phase>package</phase> <goals> <goal>single</goal> </goals> <configuration> <descriptors> <descriptor>src/main/assembly/release-linux32.xml</descriptor> </descriptors> <finalName>${project.artifactId}</finalName> <outputDirectory>${project.parent.build.directory}</outputDirectory> </configuration> </execution> <execution> <id>win64</id> <phase>package</phase> <goals> <goal>single</goal> </goals> <configuration> <descriptors> <descriptor>src/main/assembly/release-win64.xml</descriptor> </descriptors> <finalName>${project.artifactId}</finalName> <outputDirectory>${project.parent.build.directory}</outputDirectory> </configuration> </execution> <execution> <id>win32</id> <phase>package</phase> <goals> <goal>single</goal> </goals> <configuration> <descriptors> <descriptor>src/main/assembly/release-win32.xml</descriptor> </descriptors> <finalName>${project.artifactId}</finalName> <outputDirectory>${project.parent.build.directory}</outputDirectory> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles>
下面以 <id>linux64</id>的打包为例,展开讲解,linux32,win64,win32的类似
src/main/assembly/release-linux64.xml文件内容如下:
<assembly xmlns="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>linux64</id> <formats> <format>tar.gz</format> </formats> <includeBaseDirectory>true</includeBaseDirectory> <componentDescriptors> <componentDescriptor>src/main/assembly/component-linux64.xml</componentDescriptor> </componentDescriptors> </assembly>
src/main/assembly/component-linux64.xml文件内容如下:
<component> <fileSets> <fileSet> <directory>.</directory> <outputDirectory>/</outputDirectory> <includes> <include>README*</include> </includes> </fileSet> <fileSet> <directory>./linux64/bin</directory> <outputDirectory>bin</outputDirectory> <includes> <include>**/*</include> </includes> <fileMode>0755</fileMode> </fileSet> <fileSet> <directory>target</directory> <outputDirectory>logs</outputDirectory> <excludes> <exclude>**/*</exclude> </excludes> </fileSet> <fileSet> <directory>./linux64/include</directory> <outputDirectory>include</outputDirectory> <includes> <include>**/*</include> </includes> </fileSet> <fileSet> <directory>./linux64/jdk</directory> <outputDirectory>jdk</outputDirectory> <includes> <include>**/*</include> </includes> </fileSet> </fileSets> <files> <!-- <file> <source>../client-core/src/main/resources/logback.xml</source> <outputDirectory>conf</outputDirectory> </file> --> <file> <source>./target/client-deployer-0.0.1-SNAPSHOT.jar</source> <outputDirectory>include</outputDirectory> </file> <file> <source>./lib/logback-access-0.9.28.jar</source> <outputDirectory>include</outputDirectory> </file> <file> <source>./lib/logback-classic-0.9.28.jar</source> <outputDirectory>include</outputDirectory> </file> <file> <source>./lib/logback-core-0.9.28.jar</source> <outputDirectory>include</outputDirectory> </file> <file> <source>./lib/slf4j-api-1.7.2.jar</source> <outputDirectory>include</outputDirectory> </file> <file> <source>./lib/fastjson-1.1.35.jar</source> <outputDirectory>include</outputDirectory> </file> <file> <source>./lib/commons-exec-1.3.jar</source> <outputDirectory>include</outputDirectory> </file> <file> <source>./src/main/resources/version.properties</source> <outputDirectory>conf</outputDirectory> </file> <file> <source>./src/main/resources/wrapper.conf</source> <outputDirectory>conf</outputDirectory> </file> <file> <source>./src/main/resources/logback.xml</source> <outputDirectory>conf</outputDirectory> </file> <file> <source>../core/src/main/resources/client.properties</source> <outputDirectory>conf</outputDirectory> </file> </files> <dependencySets> <dependencySet> <outputDirectory>lib</outputDirectory> <excludes> <exclude>junit:junit</exclude> <exclude>org.jtester:jtester</exclude> <exclude>com.cninfo:client-deployer</exclude> </excludes> </dependencySet> </dependencySets> </component>