1、build.xml
<?xml version="1.0" encoding="UTF-8"?> <project> <!-- 将常用的定义为property属性--> <property name="build.dir" location="build"> </property> <!--使用属性定义相应的路径时,一定使用location而不要使用value--> <property name="build.classes" location="${build.dir}\classes"> </property> <property name="build.src" location="${build.dir}/src"> </property> <property name="build.lib.dir" location="${build.dir}/dist"> </property> <!--<property name="execute.class" value="com.baowei.com.HelloWorld" /> <property name="jar.name" value="hello.jar" />--> <!--如果属性太多,可以将属性放置到一个外部文件中定义,之后进行引用 特别注意:如果是路径不建议在外部文件中定义,因为此时就不会设置location的值--> <property file="build.properties"> </property> <!-- 定义文件集合 --> <fileset id="src.path" dir="src"> <include name="**/*.*" /> <!--<exclude name="**/Test*" />--> </fileset> <target name="init"> <delete dir="${build.dir}"> </delete> <mkdir dir="${build.dir}" /> <mkdir dir="${build.src}" /> <mkdir dir="${build.classes}" /> <mkdir dir="${build.lib.dir}" /> </target> <target name="copySrc" depends="init"> <copy todir="${build.src}"> <fileset refid="src.path"> </fileset> </copy> </target> <target name="compile"> <javac destdir="${build.classes}" srcdir="${build.src}"> </javac> </target> <target name="jar" depends="compile"> <jar destfile="${build.lib.dir}/${jar.name}" basedir="${build.classes}"> <manifest> <attribute name="Main-Class" value="${execute.class}" /> <attribute name="Build-By" value="Konghao" /> </manifest> </jar> </target> <target name="execute" depends="init,copySrc,compile,jar"> <echo>基于类路径的classname来完成执行</echo> <java classname="${execute.class}" classpath="${build.classes}"> </java> <echo>基于jar文件执行</echo> <java jar="${build.lib.dir}/${jar.name}" fork="true"> </java> </target> </project>
2、build.propertities
execute.class = com.baowei.com.HelloWorld
jar.name =hello.jar
时间: 2024-12-18 05:57:46