如何将Maven 项目打成 zip 包

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 文件。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值