今天开始用ant构建,所以学了下ant
<?xml version="1.0" encoding="UTF-8"?> <project name="DataClear" default="jar" basedir="."> <property file="build.properties"/>
<property environment="env"/> <property name="home" location="."/>
<property name="src" location="${home}/WEB-INF"/>
<property name="build" location="${home}/build"/>
<property name="classes" location="${build}/classes"/>
<property name="jar" location="${build}/DataClear.jar"/> <property name="tomcat.dir" location="${env.CATALINA_HOME}"/>
<property name="tomcat.dir.lib" location="${tomcat.dir}/lib"/>
<property name="java.dir" location="${env.JAVA_HOME}"/> <target name="init">
<mkdir dir="${build}"/>
<mkdir dir="${classes}"/>
</target> <path id="project.classpath">
<pathelement location="${java.dir}/jre/lib/rt.jar"/>
<pathelement location="${classes}"/> <fileset dir="${src}/lib">
<include name="*.jar"/>
</fileset> <fileset dir="${tomcat.dir.lib}">
<include name="*.jar"/>
</fileset>
</path> <target name="compile" depends="init">
<javac srcdir="${src}" destdir="${classes}" encoding="ISO8859-1">
<compilerarg value="-Xlint:unchecked"/>
<classpath refid="project.classpath"/>
</javac>
</target> <target name="jar" depends="compile">
<jar jarfile="${jar}" basedir="${classes}"
includes="**/*.class">
<fileset dir="${home}">
<include name="*.conf"/>
</fileset>
</jar>
</target> <target name="clean" depends="init">
<delete dir="${build}"/>
</target> </project>
下面我贴上一个链接,我是从他这里学会的ant,非常感谢博主,以后可以把此博文当作是ant字典,不会就去拜读,直到自己可以轻松写出xml文件。
http://my.oschina.net/willSoft/blog?disp=2&p=24
有许多朋友ant的时候出错,可能就是classpath没有配置好的缘故,如果有看到我博客的希望可以帮助到你。
另一ant构建文件:
<?xml version="1.0" encoding="UTF-8" ?> <project name="DataClear" default="jar" basedir="." > <property name="home" location="."/>
<property name="src" location="${home}/WEB-INF"/>
<property name="build" location="${home}/build"/>
<property name="classes" location="${build}/classes"/>
<property name="jar" location="${build}/DataClear.jar"/> <target name="init" description="initialize the project whose name is DataClear">
<mkdir dir="${build}"/>
<mkdir dir="${classes}"/>
</target> <path id="DataClear.lib">
<fileset dir="${src}/lib">
<include name="*.jar"/>
</fileset>
</path> <target name="compile" depends="init" description="build the files whose name is .java">
<javac srcdir="${src}/src" destdir="${classes}" encoding="ISO8859-1">
<compilerarg value="-Xlint:unchecked"/>
<classpath refid="DataClear.lib"/>
</javac>
</target> <target name="jar" depends="compile" description="create a jar file">
<jar destfile="${jar}" basedir="${classes}" includes="**/*.class">
<fileset dir="${home}">
<include name="*.conf"/>
</fileset>
</jar>
</target> <target name="clean" depends="init" description="clean the jar file and the classes files">
<delete dir="${build}"/>
<delete dir="${classes}"/>
</target> </project>