首页 > 代码库 > ant 指定生成部署文件包

ant 指定生成部署文件包

因为用到ant调用maven的场景,因此需要加入jar包 maven-ant-tasks-2.1.3.jar 随意位置,待会会在配置写标

build.properties文件配置:

#SET ENVIRONMENT PATH#maven本地仓库地址、ant_home、maven_homeM2_REPO=D:/Installed Develop/m2/RepositoryANT_HOME=D:/Installed Develop/apache-ant-1.9.4MAVEN_HOME=D:/Installed Develop/apache-maven-3.2.2#maven-ant-tasks-2.1.3.jar位置,很明显这里用了相对路径即项目根路径antlibs下ANT_TASK_JAR=antlibs

 

build.xml ant执行脚本:

 

<?xml version="1.0" encoding="UTF-8"?><project name="cloudapi-mobile" default="untar_file" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant">    <!--定义外部属性文件和目录-->    <property file="build.properties" />    <property name="deploy_dir" value="clouadpi-mobile deploy" />    <!--输出配置信息-->    <target name="show_property" description="show build.properties conf">        <echo> ================== build.properties ================ </echo>        <echo>PROJECT_NAME=${ant.project.name}</echo>        <echo>M2_REPO=${M2_REPO}</echo>        <echo>ANT_HOME=${ANT_HOME}</echo>        <echo>MAVEN_HOME=${MAVEN_HOME}</echo>        <echo>ANT_TASK_JAR=${ANT_TASK_JAR}</echo>    </target>    <!-- Ant调用Maven-->    <target name="init_mvn" description="init mvn">        <path id="maven-ant-tasks.classpath" path="${ANT_TASK_JAR}/maven-ant-tasks-2.1.3.jar" />        <typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="antlib:org.apache.maven.artifact.ant" classpathref="maven-ant-tasks.classpath" />        <echo>init mvn finished..</echo>    </target>    <!--调用maven的defalut生命周期的clean阶段-->    <target name="clean" description="mvn clean" depends="init_mvn">        <artifact:mvn mavenHome="${MAVEN_HOME}" fork="true">            <arg line="clean" />        </artifact:mvn>        <echo>mvn clean finished..</echo>    </target>    <!-- 调用maven的defalut生命周期的package阶段 -->    <target name="package" description="mvn package" depends="init_mvn, clean">        <artifact:mvn mavenHome="${MAVEN_HOME}" fork="true">            <arg line="package -Dmaven.test.skip=true -Pproduction" />        </artifact:mvn>        <echo>mvn package finished..</echo>    </target>    <!--调用maven的defalut生命周期的install阶段-->    <target name="install" description="mvn install" depends="init_mvn, clean">        <artifact:mvn mavenHome="${MAVEN_HOME}" fork="true">            <arg line="install -Dmaven.test.skip=true -Pproduction" />        </artifact:mvn>        <echo>mvn install finished..</echo>    </target>    <!-- 打印maven项目信息 -->    <target name="show_project" description="show project" depends="install">        <taskdef resource="net/sf/antcontrib/antlib.xml" />        <!-- 引入父pom文件,读取pom文件的属性 -->        <artifact:pom id="projectPom" file="pom.xml" />        <echo>The project name is ${projectPom.name}</echo>        <echo>The project version is ${projectPom.version}</echo>        <echo>The build directory is ${projectPom.build.directory}</echo>        <mkdir dir="${deploy_dir}" />    </target>    <!-- 删除上次文件 -->    <target name="dele_deploy_dir" description="del deploy dir">        <delete dir="${deploy_dir}"/>    </target>    <!-- 根据列表打包文件 -->    <target name="tar_file" description="tar file" depends="dele_deploy_dir,show_project">        <echo>tar file to deploy</echo>        <tar basedir="${projectPom.build.directory}/${projectPom.name}-${projectPom.version}/" destfile="${deploy_dir}/deploylist.jar" includesfile="deploylist.txt" />    </target>    <!-- 解压压缩包 -->    <target name="untar_file" description="untar file" depends="tar_file">        <echo>untar file to deploy</echo>        <untar src="${deploy_dir}/deploylist.jar" dest="${deploy_dir}"/>    </target>    </project>

 

 

 

另外,因为打包的时候需要通过自定义文件过滤,即脚本里的deploylist.txt 下为内容

WEB-INF/**/FeedAct.classWEB-INF/**/convertServer.propertiesWEB-INF/**/cloudapi-common_mobile_only-0.2-SNAPSHOT.jar

 

生成文件如下

技术分享

ant 指定生成部署文件包