maven-assembly-plugin

  1. Customize the package plug-in
  2. Projects tend to have a lot of shell scripts, SQL scripts,.properties, and.xml configuration items, and using the Assembly plug-in makes the structure of the output clear and standardized.
  3. With shell startup script, the effect of second startup can be achieved, especially in service deployment that depends on other projects or native packages, which greatly accelerates the deployment efficiency

How to use

To use the plug-in, add the following to the Build >plugins configuration in the project POM file.

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-assembly-plugin</artifactId>
	<configuration>
		<descriptors>
			<! Assembly XML file -->
			<descriptor>src/assembly/distribution.xml</descriptor>
		</descriptors>
	</configuration>
	<executions>
		<execution>
			<! - name - >
			<id>make-assembly</id>
			<! -- Bind to package lifecycle -->
			<phase>package</phase>
			<goals>
				<! -- Flag runs only once -->
				<goal>single</goal>
			</goals>
		</execution>
	</executions>
</plugin>

Copy the code

SRC/assembly/distribution. The XML file is described below

<assembly
	xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/plugins/mavenassembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
	<id>distribution</id>
	<formats>
		<format>dir</format>
		<! -- File type -->
		<format>tar.gz</format>
	</formats>
	<moduleSets>
		<moduleSet>
			<sources>
				<excludes>
					<exclude>src/main/resources/*.properties</exclude>
					<exclude>src/main/resources/*.xml</exclude>
				</excludes>
			</sources>
		</moduleSet>
	</moduleSets>
	<fileSets>
		<fileSet>
			<! Copy all files from the doc folder in the root directory of the current project to the doc folder in the compressed file.
			<outputDirectory>/doc</outputDirectory>
			<directory>doc</directory>
			<includes>
				<include>/ * * *</include>
			</includes>
		</fileSet>
		<! -- Copy the file from the root directory of the current project to the directory of the compressed file -->
		<fileSet>
			<outputDirectory>/sql</outputDirectory>
			<directory>sql</directory>
			<includes>
				<include>*.sql</include>
			</includes>
		</fileSet>
		<! The TMP folder can be used as a temporary file directory for Java startup.
		<fileSet>
			<outputDirectory>/tmp</outputDirectory>
			<directory>target</directory>
			<excludes>
				<exclude>/ * * *</exclude>
			</excludes>
		</fileSet>
		<! Logs folder can be saved as Java startup directory -->
		<fileSet>
			<outputDirectory>/logs</outputDirectory>
			<directory>target</directory>
			<excludes>
				<exclude>/ * * *</exclude>
			</excludes>
		</fileSet>
		<fileSet>
			<outputDirectory>/run</outputDirectory>
			<directory>target</directory>
			<excludes>
				<exclude>/ * * *</exclude>
			</excludes>
		</fileSet>
		<! Get a jar file with a specific suffix as the project's startup jar -->
		<fileSet>
			<outputDirectory>/lib</outputDirectory>
			<directory>target</directory>
			<includes>
				<include>*-with-dependencies.jar</include>
			</includes>
		</fileSet>
		<! > < span style = "max-width: 100%; clear: both; min-height: 1em;
		<fileSet>
			<outputDirectory>/bin</outputDirectory>
			<directory>target/classes/bin</directory>
			<lineEnding>unix</lineEnding>
			<fileMode>0744</fileMode>
		</fileSet>
		<! Get all resources of flik under project path and package them into compressed directory.
		<fileSet>
			<outputDirectory>/flink</outputDirectory>
			<directory>flink</directory>
			<fileMode>0744</fileMode>
			<excludes>
				<exclude>*.sh</exclude>
			</excludes>
		</fileSet>
		<fileSet>
			<outputDirectory>/flink</outputDirectory>
			<directory>flink</directory>
			<fileMode>0744</fileMode>
			<includes>
				<include>*.sh</include>
			</includes>
			<lineEnding>unix</lineEnding>
		</fileSet>
		<! Get the configuration file and package it into the conf directory.
		<fileSet>
			<outputDirectory>conf</outputDirectory>
			<directory>target/classes</directory>
			<includes>
				<include>*.yaml</include>
				<include>*.yml</include>
				<include>*.properties</include>
				<include>*.setting</include>
				<include>*.xml</include>
				<include>sample/*</include>
				<include>material/*</include>
			</includes>
		</fileSet>
	</fileSets>
</assembly>

Copy the code

Using maven packaging at this point, you get a tar.gz build that uses a more powerful Maven package in conjunction with the startup script