ANT打jar包

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>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值