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了;
上一篇:爬虫——简单处理js中嵌入的json数据


下一篇:使用 Mac 的 Safari 收看 Netflix 时出现错误码「S7361-1253」如何解决?