工程目录如下,使用eclipse中的ant对此工程进行编译打包:
MonServer
| --------src
| |--------com
| |--------log4j.properties
|
| --------config
| --------lib
| --------log
| --------sh
| --------startMon.sh
[xhtml] view plaincopyprint?<?xml version="1.0"?>
<project name="MonServer" default="all" basedir=".">
<!-- source code dir-->
<property name="src.dir" value="src">
</property>
<property name="config.dir" value="config">
</property>
<property name="lib.dir" value="lib">
</property>
<property name="log.dir" value="log">
</property>
<property name="sh.dir" value="sh">
</property>
<!-- 需要引入第3方jar包才能编译通过java文件并生成class文件,并且在target compile中应用classpath -->
<path id="classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</path>
<!-- build dir-->
<property name="build.dir" value="build">
</property>
<property name="build.classes" value="${build.dir}/classes">
</property>
<property name="build.config" value="${build.dir}/config">
</property>
<property name="build.lib" value="${build.dir}/lib">
</property>
<property name="build.log" value="${build.dir}/log">
</property>
<property name="build.sh" value="${build.dir}/sh">
</property>
<!-- remove all generated files -->
<target name="clean" description="remove all generated files">
<delete dir="${build.dir}">
</delete>
</target>
<!-- create the build dir, and copy [config,lib,sh] dir files-->
<target name="prepare">
<mkdir dir="${build.dir}" />
<mkdir dir="${build.classes}" />
<mkdir dir="${build.config}" />
<mkdir dir="${build.lib}" />
<mkdir dir="${build.log}" />
<mkdir dir="${build.sh}" />
<copy todir="${build.config}">
<fileset dir="${config.dir}" includes="*.*">
</fileset>
</copy>
<copy todir="${build.lib}">
<fileset dir="${lib.dir}" includes="*.jar">
</fileset>
</copy>
<copy todir="${build.sh}">
<fileset dir="${sh.dir}" includes="*.sh">
</fileset>
</copy>
<!-- 复制工程根目录下的文件到build目录下,如:startMon.sh-->
<copy todir="${build.dir}">
<fileset dir="." includes="*.sh">
</fileset>
</copy>
</target>
<!--compile java files, and copy other properties files -->
<target name="compile" depends="prepare" description="compile all source code">
<javac srcdir="${src.dir}" destdir="${build.classes}">
<classpath refid="classpath">
</classpath>
<compilerarg line="-encoding gbk" />
</javac>
<copy todir="${build.classes}">
<fileset dir="${src.dir}" includes="*.properties">
</fileset>
</copy>
<!--打包-->
<zip destfile="MonServer.zip" basedir="${build.dir}">
</zip>
</target>
<!-- 先编译打包,再删除目录-->
<target name="all" depends="compile,clean" description="clean,compile">
</target>
</project>
<?xml version="1.0"?>
<project name="MonServer" default="all" basedir=".">
<!-- source code dir-->
<property name="src.dir" value="src">
</property>
<property name="config.dir" value="config">
</property>
<property name="lib.dir" value="lib">
</property>
<property name="log.dir" value="log">
</property>
<property name="sh.dir" value="sh">
</property>
<!-- 需要引入第3方jar包才能编译通过java文件并生成class文件,并且在target compile中应用classpath -->
<path id="classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</path>
<!-- build dir-->
<property name="build.dir" value="build">
</property>
<property name="build.classes" value="${build.dir}/classes">
</property>
<property name="build.config" value="${build.dir}/config">
</property>
<property name="build.lib" value="${build.dir}/lib">
</property>
<property name="build.log" value="${build.dir}/log">
</property>
<property name="build.sh" value="${build.dir}/sh">
</property>
<!-- remove all generated files -->
<target name="clean" description="remove all generated files">
<delete dir="${build.dir}">
</delete>
</target>
<!-- create the build dir, and copy [config,lib,sh] dir files-->
<target name="prepare">
<mkdir dir="${build.dir}" />
<mkdir dir="${build.classes}" />
<mkdir dir="${build.config}" />
<mkdir dir="${build.lib}" />
<mkdir dir="${build.log}" />
<mkdir dir="${build.sh}" />
<copy todir="${build.config}">
<fileset dir="${config.dir}" includes="*.*">
</fileset>
</copy>
<copy todir="${build.lib}">
<fileset dir="${lib.dir}" includes="*.jar">
</fileset>
</copy>
<copy todir="${build.sh}">
<fileset dir="${sh.dir}" includes="*.sh">
</fileset>
</copy>
<!-- 复制工程根目录下的文件到build目录下,如:startMon.sh-->
<copy todir="${build.dir}">
<fileset dir="." includes="*.sh">
</fileset>
</copy>
</target>
<!--compile java files, and copy other properties files -->
<target name="compile" depends="prepare" description="compile all source code">
<javac srcdir="${src.dir}" destdir="${build.classes}">
<classpath refid="classpath">
</classpath>
<compilerarg line="-encoding gbk" />
</javac>
<copy todir="${build.classes}">
<fileset dir="${src.dir}" includes="*.properties">
</fileset>
</copy>
<!--打包-->
<zip destfile="MonServer.zip" basedir="${build.dir}">
</zip>
</target>
<!-- 先编译打包,再删除目录-->
<target name="all" depends="compile,clean" description="clean,compile">
</target>
</project>
转自 http://zhaiyue-program.iteye.com/blog/1731714