Ant入门教程,使用Ant自动生成JAR文件

Ant配置文件代码如下,具体代码下载附件
<?xml version="1.0" ?>
<project name="structured" default="all" basedir=".">

	<description>Compiles and runs a simple program</description>

	<property name="app.name" value="AntProject" />
	<property name="app.jar" value="${app.name}.jar" />

	<property name="lib.dir" value="lib" />
	<property name="src.dir" location="src" />


	<property name="build.dir" location="build" />
	<property name="dist.dir" location="dist" />

	<target name="init">
		<mkdir dir="${build.dir}" />
		<mkdir dir="${dist.dir}" />
		<mkdir dir="${build.dir}/lib" />
	</target>

	<target name="compile" depends="init" description="Compiles the source code">
		<javac srcdir="${src.dir}" destdir="${build.dir}" source="1.6" target="1.6" debug="on" />
		<copy todir="${build.dir}">
			<fileset dir="${src.dir}">
				<include name="*.xml" />
				<include name="*.properties" />
			</fileset>
		</copy>
		<copy todir="${build.dir}/lib">
			<fileset dir="${lib.dir}">
				<include name="**/*.jar" />
			</fileset>
		</copy>
	</target>

	<target name="dist" depends="compile" description="generate the distribution">
		<jar jarfile="${dist.dir}/${app.jar}" basedir="${build.dir}" />
	</target>

	<target name="clean" description="Removes the temporary directories used">
		<delete dir="${build.dir}/lib">
		</delete>
		<delete dir="${build.dir}" />
		<delete dir="${dist.dir}" />
	</target>

	<target name="execute" depends="compile" description="Runs the program">
		<echo level="warning" message="running" />
		<java classname="com.tyler4life.ant.HelloWorld" classpath="${build.dir}">
			<arg value="a" />
			<arg value="b" />
			<arg file="." />
		</java>
	</target>

	<target name="all" depends="clean,init,dist" description="Clean,build,dist" />

</project>

你可能感兴趣的:(java,xml,ant)