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内置的描述符有bin、jar-with-dependencies、src、project这几种;
mainClass:指定main方法入口,指定后在MANIFEST.MF会生成Main-Class属性,这样便可以通过
java -jar mainClass
的方式运行jar了;