Maven assembly plugin of < maven>maven plug-in

What

It is a standard plug-in for packaging tasks in maven

The main purpose of the Assembly plug-in is to allow users to assemble project output with its dependencies, modules, site documents, and other files into a distributable archive.

Why

Other plug-ins are not easy to use and each has its own short board. For example, you can't make a package based on the last package

How

1. Define pom plug-in first

			<plugin>
				<artifactId>maven-assembly-plugin</artifactId>
				<configuration>
                    <descriptors>
                        <descriptor>src/main/resources/build-jar.xml</descriptor>
                        <descriptor>src/main/resources/build-zip.xml</descriptor>
                        <!--Corresponding to src/main/resource Create under package buildzip.xml configuration file-->
                    </descriptors>
				</configuration>
				<executions>
					<execution>
						<id>make-assembly</id>
						<phase>package</phase>  <!--Packaging phase execution -->
						<goals>
							<goal>single</goal>  <!--Execute once -->
						</goals>
					</execution>
				</executions>
			</plugin>

2. Define xml

For example: build-jar.xml

<?xml version='1.0' encoding='UTF-8'?>
<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>build-jar</id>
	<formats>
		<format>jar</format>
	</formats>
	<includeBaseDirectory>false</includeBaseDirectory>

	<fileSets>
		<fileSet>
			<directory>${project.build.directory}/classes</directory>
			<includes>
				<include>**/*.class</include>
			</includes>
			<outputDirectory>/</outputDirectory>
			<fileMode>0755</fileMode> 
		</fileSet>
	</fileSets>

</assembly>

Type all the. class files under classess in the build directory into jar packages

deatail

<?xml version="1.0" encoding="utf-8"?>
<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/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
    
    <!-- id Identifier, a suffix added to the name of the build file. If specified id Words,The target file is ${artifactId}-${id}.jar. [as demo-5.0.0.0.jar] -->
    <id>${project.version}</id>
    
    <!-- Specifies the packaging format. Supported packaging formats are zip,tar,tar.gz (or tgz),tar.bz2 (or tbz2),jar,dir,war,Multiple packaging formats can be specified at the same time -->
    <formats>
        <format>war</format>
    </formats>
    
    <!-- Specifies whether the package contains the package layer directory (for example finalName yes demo,Duty is true,All files are in the package demo/Directory, otherwise it will be placed directly in the root directory of the package)-->
    <includeBaseDirectory>true</includeBaseDirectory>
    
    <!-- Specify to print the project dependent package to the specified directory in the package -->
    <dependencySets>
        <dependencySet>
            <useProjectArtifact>true</useProjectArtifact> <!-- Specifies whether to include the self generated jar package -->
            <outputDirectory>WEB-INF/lib</outputDirectory> <!-- Specify to package these dependent packages lib Directory -->
            <scope>runtime</scope> <!-- For managing dependent deployments, runtime Indicates use only at run time -->
        </dependencySet>
    </dependencySets>
    
    <!-- Specify the file set to include, you can define multiple fileSet -->
    <fileSets>
        <fileSet>
            <directory>src/main/script/linux/bin</directory> <!-- Specify the archive file (to be typed jar Package) directory to include (files and folders under) -->
            <outputDirectory>bin</outputDirectory> <!-- Specifies that the current directory(<directory>The directory in the tag is placed in the archive file (to be typed jar Package) bin Directory] -->
            <includes>
                <include>linux</include> <!-- Control exactly what files to include,<exclude>For precise control of files to exclude  -->
                <include>windows</include>
            </includes>
            <fileMode>0755</fileMode> <!-- set up file UNIX Property is a read-write permission -->
        </fileSet>  

		<!--take build-jar.xml Taxi jar package copy -->
		<fileSet>
			<directory>/target</directory>
			<includes>
				<include>*-build-jar.jar</include>
			</includes>
			<outputDirectory>WEB-INF/lib</outputDirectory>
			<fileMode>0755</fileMode> 
		</fileSet>  

		<fileSet>  
			<directory>src/main/resources</directory>
			<includes>
				<include>**/*.*</include>
			</includes>
			<excludes>
			    <exclude>/lib/*</exclude>
			</excludes>
			<outputDirectory>WEB-INF/classes/</outputDirectory>
			<fileMode>0755</fileMode> 
		</fileSet>    

    </fileSets>
    
</assembly>

Reference resources:

https://www.liangzl.com/get-article-detail-20797.html

Keywords: Maven xml Apache encoding

Added by kenhess on Sat, 16 Nov 2019 21:56:47 +0200