赞
踩
springboot项目打包,可以当依赖包用也可以当可执行包用
1、项目 java目录下新建目录assembly
添加文件assembly.xml
<?xml version="1.0" encoding="utf-8"?> <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> <!-- id 标识符,添加到生成文件名称的后缀符。如果指定 id 的话(这里指定的是项目的版本),目标文件则是 ${artifactId}-${id}.jar。【如yigo-core.jar】 --> <id>jar-with-dependencies</id> <!-- 指定打包格式。maven-assembly-plugin插件支持的打包格式有zip、tar、tar.gz (or tgz)、tar.bz2 (or tbz2)、jar、dir、war,可以同时指定多个打包格式 --> <formats> <format>jar</format> </formats> <!-- 指定打的包是否包含打包层目录(比如finalName是yigo-core,当值为true,所有文件被放在包内的yigo-core目录下,否则直接放在包的根目录下)--> <includeBaseDirectory>false</includeBaseDirectory> <dependencySets> <dependencySet> <outputDirectory>/</outputDirectory> <useProjectArtifact>true</useProjectArtifact> <unpack>true</unpack> </dependencySet> </dependencySets> <!-- <!– 指定将工程依赖的包打到包里的指定目录下 –>--> <!-- <dependencySets>--> <!-- <dependencySet>--> <!-- <useProjectArtifact>true</useProjectArtifact> <!– 指定打包时是否包含工程自身生成的jar包 –>--> <!-- <outputDirectory>lib</outputDirectory> <!– 指定将这些依赖包打到包里lib目录下 –>--> <!-- <scope>runtime</scope> <!– 用于管理依赖的部署,runtime表示只在运行时使用 –>--> <!-- </dependencySet>--> <!-- </dependencySets>--> <containerDescriptorHandlers> <containerDescriptorHandler> <handlerName>metaInf-spring</handlerName> </containerDescriptorHandler> </containerDescriptorHandlers> <fileSets> <fileSet> <directory>${project.build.directory}/classes</directory> <outputDirectory>.</outputDirectory> </fileSet> </fileSets> </assembly>
2、pom.xml中添加
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>3.3.0</version> <executions> <execution> <id>release</id> <phase>package</phase> <goals> <goal>single</goal> </goals> <configuration> <archive> <manifest> <addClasspath>false</addClasspath> <classpathPrefix>lib/</classpathPrefix> <classpathLayoutType>repository</classpathLayoutType> <mainClass>com.demo.first.FirstApplication</mainClass> </manifest> </archive> <appendAssemblyId>true</appendAssemblyId> <descriptors> <descriptor>src/assembly/assembly.xml</descriptor> </descriptors> <outputDirectory>${project.build.directory}</outputDirectory> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。