ant命令征集详解

ANT指令build.xml命令集

1.ANT示例1.0(将指定路径下的文件复制到指定的其他位置)


<?xml version="1.0" encoding="UTF-8" ?>
<project name="antTest" default="compile" basedir=".">
    <target name="clean">
        <delete dir="build" />
    </target>
    <target name="compile" depends="clean">
        <mkdir dir="build/classes" />
        <javac srcdir="src" destdir="build/classes" />
    </target>
</project>

2.ANT示例1.1(编译、运行项目antTest)

<project default="copyfile" basedir="." >
  <target name="copyfile">
		<copy file="d:/a.txt" todir="e:/Temp" overwrite="true" />
	</target>
</project>


3. ANT示例1.2(编译、运行项目antTest)

<?xml version="1.0" encoding="UTF-8" ?>
<project name="antTest" 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 file="${hello_jar}" />
	</target>
	<target name="rerun" depends="clean,run">
		<ant target="clean" />
		<ant target="run" />
	</target>
</project>

4. ANT示例1.3(编译、运行项目antTest)

<?xml version="1.0" encoding="UTF-8" ?>
<project name="antTest" default="war" basedir=".">
	<property name="classes" value="build/classes" />
	<property name="build" value="build" />
	<property name="lib" value="WebRoot/WEB-INF/lib" />
	<!-- 删除build路径-->
	<target name="clean">
		<delete dir="build" />
	</target>

	<!-- 建立build/classes路径,并编译class文件到build/classes路径下-->
	<target name="compile" depends="clean">
		<mkdir dir="${classes}" />
		<javac srcdir="src" destdir="${classes}" includeantruntime="on" />
	</target>

	<!-- 打war包-->
	<target name="war" depends="compile">
		<war destfile="${build}/antTest.war" webxml="WebRoot/WEB-INF/web.xml">
			<!-- 拷贝WebRoot下除了WEB-INF和META-INF的两个文件夹-->
			<fileset dir="WebRoot" includes="**/*.jsp" />

			<!-- 拷贝lib目录下的jar包-->
			<lib dir="${lib}" />
			<!-- 拷贝build/classes下的class文件-->
			<classes dir="${classes}"/>
		</war>
	</target>
</project>

5. ANT示例1.4(编译、运行项目antTest)

<?xml version="1.0" encoding="UTF-8" ?>
<project name="antTest" 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 file="${hello_jar}" />
	</target>
	<target name="rerun" depends="clean,run">
		<ant target="clean" />
		<ant target="run" />
	</target>
</project>

6. ANT示例1.5(编译、运行项目)复杂的配置


<?xml version="1.0" encoding="UTF-8"?>

<project name="antTest" basedir="." default="pack.web">
	<property name="build.debug" value="on" />
	<property name="build.debug.level" value="lines,vars,source" />
	<property name="compile.deprecation" value="false" />
	<property name="compile.optimize" value="true" />
	<property name="source.excludes" value="applicationContext.xml, jdbc.properties " />
	<property name="portal.opensource.excludes" value="wlclient.jar,servlet-api.jar,j2ee.jar" />
	<property name="lib.dev.excludes" value="a.jar" />
	<property name="source.dao.dir" value="${basedir}/../dao" />
	<property name="source.mgr.dir" value="${basedir}/../mgr" />
	<property name="source.portal.dir" value="${basedir}/../web" />
	<property name="build.dir" value="c:/web" />
	<property name="lib.dir" value="${basedir}/../libIbssPub" />
	<property name="lib.dev.dir" value="${lib.dir}/dev" />
	<property name="lib.opensource.dir" value="${lib.dir}/opensource" />
	<property name="lib.weblogic.dir" value="${lib.dir}/weblogic" />
	<target name="clean">
		<delete dir="${build.dir}" />
		<mkdir dir="${build.dir}/mgr" />
		<mkdir dir="${build.dir}/dao" />
	</target>
	<path id="general.compile.classpath">
		<fileset dir="${lib.opensource.dir}" includes="**/*.jar" />
		<fileset dir="${lib.dev.dir}" includes="**/*.jar" />
		<fileset dir="${lib.weblogic.dir}" includes="**/*.jar" />
	</path>
	<target name="compile.mgr">
		<javac destdir="${build.dir}/mgr" encoding="GBK" debug="${build.debug}" debuglevel="${build.debug.level}" deprecation="${compile.deprecation}" optimize="${compile.optimize}">
			<src path="${source.mgr.dir}/src" />
			<classpath refid="general.compile.classpath" />
			<classpath>
				<fileset file="${build.dir}/dao.jar" />
			</classpath>
		</javac>
		<copy todir="${build.dir}/mgr">
			<fileset dir="${source.mgr.dir}/src" excludes="**/*.java,  **/*.class, log4j.properties, ${source.excludes}" />
		</copy>
	</target>
	<target name="compile.dao">
		<javac srcdir="${source.dao.dir}/src" destdir="${build.dir}/dao" encoding="GBK" debug="${build.debug}" debuglevel="${build.debug.level}" deprecation="${compile.deprecation}" optimize="${compile.optimize}">
			<classpath refid="general.compile.classpath" />
		</javac>
		<copy todir="${build.dir}/dao" overwrite="true">
			<fileset dir="${source.dao.dir}/src" excludes="**/*.java, **/*.class, log4j.properties, ${source.excludes}" />
		</copy>
	</target>
	<target name="pack.dao" depends="compile.dao">
		<delete file="${build.dir}/dao.jar" />
		<jar destfile="${build.dir}/dao.jar">
			<fileset dir="${build.dir}/dao" />
		</jar>
	</target>
	<target name="pack.mgr" depends="compile.mgr">
		<delete file="${build.dir}/mgr.jar" />
		<jar destfile="${build.dir}/mgr.jar">
			<fileset dir="${build.dir}/mgr" />
		</jar>
	</target>
	<target name="pack.portal">
		<war destfile="${build.dir}/web.war" webxml="${source.portal.dir}/WebRoot/WEB-INF/web.xml">
			<fileset dir="${source.portal.dir}/WebRoot" />
			<lib dir="${lib.dev.dir}" excludes="${lib.dev.excludes}" />
			<lib dir="${lib.opensource.dir}" excludes="${portal.opensource.excludes}" />
			<lib dir="${build.dir}" includes="*.jar" />
		</war>
	</target>
	<target name="pack.web" description="打包WEB">
		<echo file="${source.portal.dir}/src/jdbc.properties" append="false" message="jdbc.driverClassName=oracle.jdbc.driver.OracleDriver${line.separator}" />
		<echo file="${source.portal.dir}/src/jdbc.properties" append="true" message="jdbc.url=jdbc:oracle:thin:@127.0.0.1:1521:orcl${line.separator}" />
		<echo file="${source.portal.dir}/src/jdbc.properties" append="true" message="jdbc.username=web_dev${line.separator}" />
		<echo file="${source.portal.dir}/src/jdbc.properties" append="true" message="jdbc.password=devweb${line.separator}" />
		<echo file="${source.portal.dir}/src/jdbc.properties" append="true" message="datasource.name=jdbc/web${line.separator}" />
		<antcall target="clean" />
		<antcall target="pack.dao" />
		<antcall target="pack.mgr" />
		<delete dir="${build.dir}/mgr" />
		<delete dir="${build.dir}/dao" />
		<antcall target="pack.portal" />
		<exec executable="cmd.exe">
			<arg value="/c" />
			<arg value="start ${build.dir}" />
		</exec>
	</target>
	<property name="tomcat.home" value="D:/apache-tomcat-6.0.20" />
	<target name="deploy.tomcat" description="部署到tomcat">
		<copy todir="${tomcat.home}/webapps" overwrite="true">
			<fileset dir="${build.dir}" includes="web.war" />
		</copy>
	</target>
	<target name="tomcat.start">
		<java jar="${tomcat.home}/bin/bootstrap.jar" fork="true">
			<jvmarg value="-Dcatalina.home=${tomcat.home}" />
			<jvmarg value="-Dsys.run.environment=SPS" />
			<jvmarg value="-Xdebug" />
		</java>
	</target>
	<target name="tomcat.stop">
		<java jar="${tomcat.home}/bin/bootstrap.jar" fork="true">
			<jvmarg value="-Dcatalina.home=${tomcat.home}" />
			<arg line="stop" />
		</java>
	</target>
</project>

贴上图片: ant命令征集详解_第1张图片


ant命令征集详解_第2张图片


ant命令征集详解_第3张图片

ant命令征集详解_第4张图片


ant命令征集详解_第5张图片


ant命令征集详解_第6张图片


ant命令征集详解_第7张图片


ant命令征集详解_第8张图片

ANT的命令到此结束。他们的依赖关系,大家细细琢磨。本人目前已经不使用ANT脚本很久了。目前使用的mavenmavenANT好多了,具体好在哪里大家可以到网上搜一搜。等以后有时间了给大家贡献maven的讲解。请大家多多关注本人的博客!!

项目实例下载路径:HTTP://download.csdn.net/detail/xmt1139057136/7112943

相关文档下载路径:HTTP://download.csdn.net/download/xmt1139057136/7113051


你可能感兴趣的:(maven,ant,java打包,java编译,构建工具)