Ant脚本模板,仅供参考

以下脚本来自Ant官方文档:

number1:

<project name="MyProject" default="dist" basedir=".">
    <description>
        simple example build file
    </description>
  <!-- set global properties for this build -->
  <property name="src" location="src"/>
  <property name="build" location="build"/>
  <property name="dist"  location="dist"/>

  <target name="init">
    <!-- Create the time stamp -->
    <tstamp/>
    <!-- Create the build directory structure used by compile -->
    <mkdir dir="${build}"/>
  </target>

  <target name="compile" depends="init"
        description="compile the source " >
    <!-- Compile the java code from ${src} into ${build} -->
    <javac srcdir="${src}" destdir="${build}"/>
  </target>

  <target name="dist" depends="compile"
        description="generate the distribution" >
    <!-- Create the distribution directory -->
    <mkdir dir="${dist}/lib"/>

    <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
    <jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/>
  </target>

  <target name="clean"
        description="clean up" >
    <!-- Delete the ${build} and ${dist} directory trees -->
    <delete dir="${build}"/>
    <delete dir="${dist}"/>
  </target>
</project>

number2:

<?xml version="1.0" encoding="UTF-8"?>
<project name="HelloWorld" default="run" basedir=".">
	<property name = "src" value = "src"/>
	<property name = "dest" value = "classes"/>
	<property name = "hello_jar" value = "hello1.jar"/>
    <target name="init">
       <mkdir dir = "${dest}"/>
    </target>
    <target name="compile" depends = "init">
       <javac srcdir = "${src}" destdir = "${dest}"/>
    </target>
    <target name="build" depends = "compile">
       <jar jarfile = "${hello_jar}" basedir = "${dest}"/>
    </target>
    <target name="run" depends = "build">
       <java classname = "test.ant.HelloWorld" classpath = "${hello_jar}"/>
    </target>
    <target name="clean">
       <delete dir = "${dest}"/>
       <delete dir = "${hello_jar}"/>
    </target>
    <target name="rerun" depends = "clean,run">
       <ant target = "clean"/>
       <ant target = "run"/>
    </target>
</project>

number3:

<project name="MyProject" default="myTarget" basedir=".">
    <target name="myTarget" depends="myTarget.check" if="myTarget.run">
    	<echo>Files a.txt and b.txt are present.</echo>
    </target>
    <target name="myTarget.check">
    	<condition property="myTarget.run">
    		<and>
    			<available file="a.txt"/>
    			<available file="b.txt"/>
            </and>
        </condition>
    </target>
</project>

number4:

<project name="HelloWorld" default="lots-of-stuff" basedir=".">
    <target name="-check-use-file">
    	<available property="file.exists" file="some-file"/>
    </target>
    <target name="use-file" depends="-check-use-file" if="file.exists">
    	<!-- do something requiring that file... -->
    </target>
    <target name="lots-of-stuff" depends="use-file,other-unconditional-stuff">
    </target>
</project>

number5:

<property file="my-prefs.properties"/>
<target name="print-message" unless="${skip.printing.message}">
    <echo>hello!</echo>
</target>

number6:

<target name="-check-use-file" unless="file.exists">
    <available property="file.exists" file="some-file"/>
</target>
<target name="use-file" depends="-check-use-file" if="${file.exists}">
    <!-- do something requiring that file... -->
</target>
<target name="lots-of-stuff" depends="use-file,other-unconditional-stuff"/>

number7:

	<project default = "help">
		<property name = "db.user" value = "wangbisheng"/>
		<target name = "Input">
			<input
				message = "Please enter db-username: "
				addproperty = "db.user"
				defaultvalue = "Scott-Tiger"
				/>
			<echo>"${db.user}"</echo>
	    </target>
	    <target name = "help">
	    	<java classname = "myname" classpath = "."/>
	    </target>
	</project>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值