Ant常用代码段

Ant的介绍网上很多,就不赘述了。

可参照:

http://www.blogjava.net/zhengtengfeng/archive/2007/04/20/zhtfeng.html

直接看例子:

<?xml version="1.0" encoding="UTF-8"?>
<project name="build_test" basedir=".">
    <!-- 
        import build.properties
        [build.properties]
        tomcat.home=D:/apache_tomcat_6.0.9    
    -->
    <property file="build.properties" />


    <property environment="env"/>
    <property name="SystemRoot.path" value="${env.SystemRoot}" />
    <property name="ANT_HOME.path" value="${env.ANT_HOME}" />
    <property name="OS.type" value="${env.OS}" />
    <target name="show-properties">
        <echo message="System Root: ${SystemRoot.path}" />
        <echo message="OS Type: ${OS.type}" />
        <echo message="Ant Home:${ant.home}" />
        <echo message="Ant Version:${ant.version}" />
        <echo message="Java Version:${ant.java.version}" />
    </target>


    <!-- start tomcat-->
    <target name="start-tomcat" description="start tomcat">
        <exec executable="${tomcat.home}/bin/startup.bat" spawn="true" vmlauncher="false">
            <env key="CATALINA_HOME" value="${tomcat.home}"/>
        </exec>
    </target>

    <!-- stop tomcat-->
    <target name="stop-tomcat" description="stop tomcat">
        <exec executable="${tomcat.home}/bin/shutdown.bat" spawn="true" vmlauncher="false">
            <env key="CATALINA_HOME" value="${tomcat.home}"/>
        </exec>
    </target>


    <!-- start browser-->
    <target name="open-browser">
        <exec executable="cmd">
            <arg line="/c start http://www.baidu.com" />
        </exec>
    </target>

    <!-- load file-->
    <target name="load-file">
        <loadfile property="MessageFromFile" srcFile="ContentInFile.txt"/>
        <echo  message="${MessageFromFile}" />
    </target>

</project>

有时候我们需要打一个jar包,jar包中需要有一个“META-INF”文件夹,里面创建一个“MANIFEST.MF”文件,下面的代码就能帮你实现:

<jar jarfile="${jspdir}/WEB-INF/lib/test.jar" basedir="${destdir}" includes="com/XXX/**">
    <!-- define MANIFEST.MF -->
    <manifest>
        <attribute name="Manifest-Version" value="1.0" />
        <attribute name="Class-Path" value="" />
        <attribute name="Description" value="test." />
    </manifest>
    <metainf dir="./WEB-INF/tlds">
        <include name="*.tld"/> <!-- 拷贝一个tld文件到“META-INF”文件夹中 -->
    </metainf>
</jar>

更多示例代码段,可参照:

http://rensanning.iteye.com/blog/1540336

原文地址:https://www.cnblogs.com/yejg1212/p/2955870.html