Example of dir1-assembly.xml
The following is an example dir1-assembly.xml
descriptor file for building src/main/resources/dir1
a JAR against a directory:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>dir1-assembly</id>
<formats>
<format>jar</format>
</formats>
<fileSets>
<fileSet>
<directory>src/main/resources/dir1</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
</assembly>
In the above example, we defined an <assembly>
element specifying the namespace and version of the descriptor file.
<id>
element specifies the ID of the descriptor file, corresponding to the element in pom.xml
.<execution>
assemblyId
<formats>
The element specifies the format of the JAR package to be generated, here it is set to jar
.
<fileSets>
element defines the collection of files to include. In this example, we define an <fileSet>
element specifying src/main/resources/dir1
directories as source directories to include and output to the root directory ( /
).
You can add other <fileSet>
elements to the descriptor file as needed to include more directories and files.
Hope this example helps you understand how to write dir1-assembly.xml
a descriptor file to build src/main/resources/dir1
a directory-specific JAR package. Please make appropriate adjustments according to your project structure and needs.
Build multiple jar packages according to different configuration files
To build different JAR packages according to different directories, maven-assembly-plugin
multiple configurations can be used to achieve.
The following is an example configuration that demonstrates how to use maven-assembly-plugin
different directories to build different JAR packages:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>dir1-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/dir1-assembly.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
<execution>
<id>dir2-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/dir2-assembly.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
In the above example, we defined two <execution>
elements in the configuration section of the plugin, corresponding to builds of dir1
and .dir2
In each <execution>
element, we specify a custom descriptor file, such as src/main/assembly/dir1-assembly.xml
and src/main/assembly/dir2-assembly.xml
, corresponding to the configuration of dir1
and respectively dir2
.
In each descriptor file, you define which directories, files, and other resources need to be included. You can configure it as needed to meet the needs of a specific directory.
When executing the command, the following command can be used to build a specific JAR package:
mvn clean package -DassemblyId=dir1-assembly
or
mvn clean package -DassemblyId=dir2-assembly
Wherein, -DassemblyId
the parameter specifies the ID of the JAR package to be built, that is, the ID corresponding to the descriptor file.
Hope this example can help you build different JAR packages according to different directories. Please make appropriate adjustments according to your project structure and needs.