The project has a requirement to package the code and dependencies of the current project into a jar package, and then package the jar package with some related files into a tar
Two plugins are used here, shade and assembly,shade are responsible for generating the jar package, and assembly is responsible for packaging it into tar. The Pom.xml configuration is as follows:
<build> <plugins> <plugin> <groupId> org.apache.maven.plugins</groupid> <artifactId>maven-shade-plugin</artifactId> <version>1.4</version> <executions > <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <finalname>abc-service</finalname> //Package name <transformers> <transformer implementation= " Org.apache.maven.plugins.shade.resource.ManifestResourceTransformer "> <mainclass>com.abc.main</ mainclass> //Main class name &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&Nbsp; </transformer> </transformers> </configuration> </execution> </executions> </plugin > <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactId> maven-assembly-plugin</artifactid> <version>2.4.1</version> <configuration> <descriptors> <descriptor>assembly.xml</descriptor> </ descriptors> </configuration> </plugin> ....... </plugins ></build>
Assembly.xml defines the actions packaged as tar
<assembly> <id>beta</id> <formats> <!-- zip,tar,tar.gz,tar.bz2,jar,dir,war --> <format>tar.gz</format> </ formats> <!-- file sets that need to be packaged --> <fileSets> <fileSet> <directory>resource</directory> //Related Files directory <outputdirectory>/ </outputDirectory> </fileSet> </fileSets> <files> <file> &Nbsp; <source>${project.build.directory}/abc-service.jar </source> //Source jar Package name <outputDirectory>/</outputDirectory> <destname>abc-service.jar</destname> //tar Inside Jar Package Name </file> </files> </assembly>
In Maven's execution goals, fill in the following:
Clean Test Package assembly:assembly
Release the executable jar package with MAVEN package