1 首先,我们在项目下新建build.xml 文件,把下面的代码复制进去。
<?xml version="1.0" encoding="utf-8"?>
<project name="xxx" default="zip_all" basedir="."> <!-- xxx 指的是项目名 -->
<description>
simple example build file
</description>
<property name="app" value="xxx" /> <!-- xxx 指的是项目名 -->
<property name="dist" location="target" />
<target name="makedir">
<echo message="mkdir ${dist}/zip/${app}" />
<mkdir dir="${dist}/zip/${app}" />
<mkdir dir="${dist}/${app}" />
</target>
<target name="dist" depends="makedir" description="dist">
<copy todir="${dist}/zip/${app}">
<fileset dir="${dist}/${app}" />
</copy>
</target>
<target name="clean" description="clean up">
<!-- Delete ${dist}/zip directory trees -->
<echo message="delete ${dist}/zip/${app}" />
<delete dir="${dist}/zip" />
</target>
<target name="zip_clear" depends="clean,makedir">
<echo message="##########copy META-INF to dist!" />
<copy todir="${dist}/zip/${app}">
<fileset dir="${dist}/${app}">
</fileset>
</copy>
</target>
<target name="zip_all" depends="zip_clear">
<zip destfile="${dist}/zip/${app}.zip" basedir="${dist}/zip">
</zip>
</target>
</project>
2 在pom.xml 添加插件
//注意打包使用 war
<packaging>war</packaging>
<build>
<finalName>${project.artifactId}</finalName>
<defaultGoal>package</defaultGoal>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- ant插件 -->
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>install</id>
<phase>install</phase>
<configuration>
<tasks>
<ant antfile="${basedir}/build.xml">
<target name="zip_all"/>
</ant>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>clean</id>
<phase>clean</phase>
<configuration>
<tasks>
</tasks>
<target>
<ant antfile="${basedir}/build.xml">
<target name="zip_clear"/>
</ant>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
3 右击项目Run as → Maven clean 之后 再Maven install 一下。
4 点击target 目录 ,我们可以看到以下目录结构。
其中 包含了 xxx.zip 文件。