maven assembly打fatjar

时间:2021-08-01
本文章向大家介绍maven assembly打fatjar,主要包括maven assembly打fatjar使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

参考自Create Jar with dependencies in Maven – TechGiant

pom.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation=
                 "http://maven.apache.org/POM/4.0.0
                  http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.pozhenzi</groupId>
    <artifactId>fatjar</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <build>
        <finalName>pozhenzi</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <appendAssemblyId>false</appendAssemblyId>
                    <archive>
                        <manifest>
                            <mainClass>com.pozhenzi.Demo</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

标签说明

  • finalName:指定生成文件名称,默认为artifactId-version
  • appendAssemblyId:生成文件时,是否追加assemblyId到文件名上,这里的assemblyId即jar-with-dependencies;若选择true,生成文件名为pozhenzi-jar-with-dependencies.jar
  • descritorRef:assembly描述符的引用,assembly内置的描述符有binjar-with-dependenciessrcproject这几种;
  • mainClass:指定main方法入口,指定后在MANIFEST.MF会生成Main-Class属性,这样便可以通过java -jar mainClass的方式运行jar了;

原文地址:https://www.cnblogs.com/pozhenzi/p/15086543.html