因为项目需求,需要自动编译,打包源文件。通过eclipse导出功能,不能实现自动?编译,打包。
即决定用ant来完成,(ant可以通过 批处理文件调用)
因为项目架构比较特殊,有path1/src,path2/src,path3/src 多个同级源文件目录。
而且需要多个classpath目录,存放着需要用到的jar包。
在网上搜索,多是简单的ant配置,而后几经折磨,得到如下配置。
可以成功完成需求功能。
?
- <?xml?version="1.0"?encoding="GBK"??>??
- <!--?=====================================?-->??
- <!--?张楠?2010/01/12?-->??
- <!--?=====================================?-->??
- ??
- <!--default="clean"定义ant运行到target??clean这一步结束-->??
- <project?name="projectName"?default="clean"?basedir="D:/work/projectName">??
- ????<description>projectName系统发布</description>??
- ????<!--属性设置-->??
- ????<property?environment="env"?/>??
- ????<property?name="src.dir"?value="${basedir}/src"?/>??
- ????<property?name="jar.file"?value="projectName.jar"?/>??
- ????<property?name="java.lib.dir"?value="${env.JAVA_HOME}/lib"?/>??
- ????<property?name="build.dir"?value="${basedir}/build"?/>??
- ????<property?name="classes.dir"?value="${build.dir}/classes"?/>??
- ????<property?name="dist.dir"?value="D:/contrib"?/>??
- ??????????
- ????<!--?基本编译路径设置?定义多个classpath-->??
- ????<path?id="compile.classpath">??
- ????????<fileset?dir="${java.lib.dir}">??
- ????????????<include?name="tools.jar"?/>??
- ????????</fileset>??
- ????????<fileset?dir="D:/contrib">??
- ????????????<include?name="*.jar"?/>??
- ????????</fileset>??
- ????</path>??
- ??????
- ????<!--?运行路径设置?-->??
- ????<!--path?id="run.classpath">??
- ????????<path?refid="compile.classpath"?/>??
- ????????<pathelement?location="${classes.dir}"?/>??
- ????</path-->??
- ??????
- ????<!--?排除java源文件的模式集?-->??
- ????<patternset?id="no.java">??
- ????????<exclude?name="**/*.java"?/>??
- ????</patternset>??
- ??????
- ????<!--?初始化,建立目录,将多个src目录复制到同一src目录,编译,打包完成后自动清除?-->??
- ????<target?name="init"?description="初始化,建立目录,复制文件">??
- ????????<mkdir?dir="${classes.dir}"?/>??
- ????????<mkdir?dir="${dist.dir}"?/>??
- ????????<mkdir?dir="${src.dir}"?/>??
- ????????<copy?todir="${src.dir}">??
- ?????????????????<fileset?dir="${basedir}/path1/src">??
- ????????????????<include?name="**/*.java"?/>??
- ?????????????</fileset>??
- ????????</copy>??
- ????????<copy?todir="${src.dir}">??
- ?????????????<fileset?dir="${basedir}/path2/src">??
- ??????????????<include?name="**/*.java"?/>??
- ???????????</fileset>??
- ????????</copy>??
- ????????<copy?todir="${src.dir}">??
- ?????????????<fileset?dir="${basedir}/path3/src">??
- ??????????????<include?name="**/*.java"?/>??
- ???????????</fileset>??
- ????????</copy>??
- ????????<copy?todir="${src.dir}">??
- ?????????????<fileset?dir="${basedir}/path4/src">??
- ??????????????<include?name="**/*.java"?/>??
- ??????????</fileset>??
- ????????</copy>??
- ????????<copy?todir="${classes.dir}">??
- ????????????<fileset?dir="${src.dir}">??
- ????????????????<patternset?refid="no.java"?/>??
- ????????????</fileset>??
- ????????</copy>??
- ????</target>??
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~??
- 长期推荐成都知名外企(英语好?C++?JAVA)??
- mail?to:hot13399@163.com??
- [url]http://woshizn.iteye.com/blog/1195498[/url]??
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~??
- ????<!--?编译源文件-->??
- ????<target?name="compile"?depends="init"?description="编译源文件">??
- ????????<javac?srcdir="${src.dir}"?destdir="${classes.dir}"?source="1.5"?target="1.5">??
- ????????????<classpath?refid="compile.classpath"?/>??
- ????????</javac>??
- ????</target>??
- ??????
- ????<!--?打包类文件?-->??
- ????<target?name="jar"?depends="compile"?description="打包类文件">??
- ????????<jar?jarfile="${dist.dir}/${jar.file}"?>??
- ????????????<fileset?dir="${classes.dir}"?includes="**/*.*"?/>??
- ????????</jar>??
- ????</target>??
- ??????
- ????<!--?清理,删除临时目录?-->??
- ????<target?name="clean"?depends="jar"?description="清理,删除临时目录">??
- ????????<delete?dir="${build.dir}"?/>??
- ????????<delete?dir="${basedir}/.settings"?/>??
- ????????<delete?dir="${src.dir}"?/>??
- ????????<delete?dir="${basedir}/bin"?/>??
- ????????<echo?level="info">清理完毕</echo>??
- ????</target>??
- ??????
- ????<!--?从打包后jar的文件里运行?-->??
- ????<!--target?name="runjar"?depends="jar"?description="运行jar">??
- ????????<java?jar="${dist.dir}/${jar.file}"?fork="yes"?dir="${basedir}"?/>??
- ????</target-->??
- ??????
- ????<!--?运行?-->??
- ????<!--target?name="run"?depends="compile"?description="运行">??
- ????????<java?classname="powerwind.Sample"?fork="yes"?dir="${basedir}">??
- ????????????<classpath?refid="run.classpath"?/>??
- ????????????<arg?line="${param.msg}"?/>??
- ????????</java>??
- ????</target-->??
- </project>??
- ??
- ? ?