1.单个项目
<?xml version="1.0" ?>
<project default="jar" name="msjob">
<!-- 工程目录结构
project
|-bin
|-src
|-libs
|-bat
|-build
|-build.xml
-->
<property name="lib.dir" value="libs" />
<property name="src.dir" value="src" />
<property name="bat.dir" value="bat" />
<property name="classes.dir" value="bin" />
<property name="output.dir" value="build" />
<property name="cmccJarName" value="CMCC.jar" />
<property name="cmccMainClass" value="com.huadi.main.CMCCMain" />
<property name="cuccJarName" value="CUCC.jar" />
<property name="cuccMainClass" value="com.huadi.main.Main" />
<!-- 第三方jar包的路径 -->
<path id="lib-classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</path>
<!-- 1. 初始化工作,如创建目录等 -->
<target name="init">
<delete dir="${output.dir}" includeemptydirs="false" />
<mkdir dir="${classes.dir}" />
<mkdir dir="${output.dir}" />
<mkdir dir="${output.dir}/NotifyApp_cmcc" />
<mkdir dir="${output.dir}/NotifyApp_cucc" />
</target>
<!-- 2. 编译 -->
<target name="compile" depends="init">
<javac srcdir="${src.dir}" destdir="${classes.dir}" source="1.6" target="1.6" includeantruntime="false" encoding="utf-8" debug="on">
<compilerarg line="-encoding UTF-8" />
<classpath refid="lib-classpath" />
</javac>
<copy todir="${classes.dir}">
<fileset dir="${src.dir}">
<include name="**/*.xml" />
<include name="**/*.properties" />
</fileset>
</copy>
</target>
<!-- 3. 打包jar文件 -->
<target name="jar" depends="compile">
<!-- CMCC -->
<copy todir="${output.dir}/NotifyApp_cmcc/CMCC_lib">
<fileset dir="${lib.dir}" />
</copy>
<copy todir="${output.dir}/NotifyApp_cmcc">
<fileset dir="${bat.dir}">
<include name="cmcc.bat" />
</fileset>
</copy>
<!-- mf文件 -->
<pathconvert property="mf.classpath.cmcc" pathsep=" ">
<mapper>
<chainedmapper>
<!-- jar包文件只留文件名,去掉目录信息 -->
<flattenmapper />
<!-- add lib/ prefix -->
<globmapper from="*" to="CMCC_lib/*" />
</chainedmapper>
</mapper>
<path refid="lib-classpath" />
</pathconvert>
<!-- jar文件的输出路径 -->
<jar destfile="${output.dir}/NotifyApp_cmcc/${cmccJarName}" basedir="${classes.dir}">
<manifest>
<attribute name="Main-class" value="${cmccMainClass}" />
<attribute name="Class-Path" value="${mf.classpath.cmcc}" />
</manifest>
</jar>
<!-- CUCC -->
<copy todir="${output.dir}/NotifyApp_cucc/CUCC_lib">
<fileset dir="${lib.dir}" />
</copy>
<copy todir="${output.dir}/NotifyApp_cucc">
<fileset dir="${bat.dir}">
<include name="cucc.bat" />
</fileset>
</copy>
<!-- mf文件 -->
<pathconvert property="mf.classpath.cucc" pathsep=" ">
<mapper>
<chainedmapper>
<!-- jar包文件只留文件名,去掉目录信息 -->
<flattenmapper />
<!-- add lib/ prefix -->
<globmapper from="*" to="CUCC_lib/*" />
</chainedmapper>
</mapper>
<path refid="lib-classpath" />
</pathconvert>
<!-- jar文件的输出路径 -->
<jar destfile="${output.dir}/NotifyApp_cucc/${cuccJarName}" basedir="${classes.dir}">
<manifest>
<attribute name="Main-class" value="${cuccMainClass}" />
<attribute name="Class-Path" value="${mf.classpath.cucc}" />
</manifest>
</jar>
</target>
</project>
2.项目引用其他项目
<?xml version="1.0" ?>
<project default="jar" name="async">
<!-- 工程目录结构
project
|-bin
|-src(需要引用NMS4SZX-Common项目和OAM4SZX-JavaWatch项目的src)
|-[libs](依赖于NMS4SZX-Common项目和OAM4SZX-JavaWatch项目)
|-bat
|-target
|-build
|-build.xml
-->
<property name="common.dir" value="../NMS4SZX-Common" />
<property name="watch.dir" value="../OAM4SZX-JavaWatch" />
<property name="src.dir" value="src" />
<property name="lib.dir" value="target" />
<property name="bat.dir" value="bat" />
<property name="classes.dir" value="bin" />
<property name="output.dir" value="build" />
<property name="jarName" value="monitor_sync_wincenter.jar" />
<property name="mainClass" value="com.huadi.sync.main.ReportDataMain" />
<!-- 第三方jar包的路径 -->
<path id="lib-classpath">
<fileset dir="${common.dir}/lib">
<include name="**/*.jar" />
</fileset>
<fileset dir="${common.dir}/lib_m">
<include name="**/*.jar" />
</fileset>
<fileset dir="${common.dir}/lib_m_xen">
<include name="**/*.jar" />
</fileset>
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</path>
<!-- 1. 初始化工作,如创建目录等 -->
<target name="init">
<delete dir="${output.dir}" includeemptydirs="false" />
<mkdir dir="${classes.dir}" />
<mkdir dir="${output.dir}" />
<mkdir dir="${output.dir}/WCESyncApp" />
<mkdir dir="${output.dir}/WCESyncApp/monitor_sync_wincenter_lib" />
</target>
<!-- 2. 编译 -->
<target name="compile" depends="init">
<!-- 编译common项目 -->
<javac srcdir="${common.dir}/src" destdir="${classes.dir}" source="1.6" target="1.6" includeantruntime="false" encoding="utf-8" debug="on">
<compilerarg line="-encoding UTF-8" />
<classpath refid="lib-classpath" />
</javac>
<copy todir="${classes.dir}">
<fileset dir="${common.dir}/src">
<include name="**/*.xml" />
<include name="**/*.properties" />
</fileset>
</copy>
<!-- 编译watch项目 -->
<javac srcdir="${watch.dir}/src" destdir="${classes.dir}" source="1.6" target="1.6" includeantruntime="false" encoding="utf-8" debug="on">
<compilerarg line="-encoding UTF-8" />
<classpath refid="lib-classpath" />
</javac>
<copy todir="${classes.dir}">
<fileset dir="${watch.dir}/src">
<include name="**/*.xml" />
<include name="**/*.properties" />
</fileset>
</copy>
<!-- 编译inputServer项目 -->
<javac srcdir="${src.dir}" destdir="${classes.dir}" source="1.6" target="1.6" includeantruntime="false" encoding="utf-8" debug="on">
<compilerarg line="-encoding UTF-8" />
<classpath refid="lib-classpath" />
</javac>
<copy todir="${classes.dir}">
<fileset dir="${src.dir}">
<include name="**/*.xml" />
<include name="**/*.properties" />
</fileset>
</copy>
</target>
<!-- 3. 打包jar文件 -->
<target name="jar" depends="compile">
<copy todir="${output.dir}/WCESyncApp/monitor_sync_wincenter_lib">
<fileset dir="${common.dir}/lib">
<include name="**/*.jar" />
</fileset>
<fileset dir="${common.dir}/lib_m">
<include name="**/*.jar" />
</fileset>
<fileset dir="${common.dir}/lib_m_xen">
<include name="**/*.jar" />
</fileset>
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</copy>
<copy todir="${output.dir}/WCESyncApp">
<fileset dir="${bat.dir}">
<include name="monitor_sync_wincenter.bat" />
</fileset>
</copy>
<!-- mf文件 -->
<pathconvert property="mf.classpath" pathsep=" ">
<mapper>
<chainedmapper>
<!-- jar包文件只留文件名,去掉目录信息 -->
<flattenmapper />
<!-- add lib/ prefix -->
<globmapper from="*" to="monitor_sync_wincenter_lib/*" />
</chainedmapper>
</mapper>
<path refid="lib-classpath" />
</pathconvert>
<!-- jar文件的输出路径 -->
<jar destfile="${output.dir}/WCESyncApp/${jarName}" basedir="${classes.dir}">
<manifest>
<attribute name="Main-class" value="${mainClass}" />
<attribute name="Class-Path" value="${mf.classpath}" />
</manifest>
</jar>
</target>
</project>