ant编译打包build.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<!--开始 project 开始编译 basedir为当前的目录 -->
<project name="TestServer" basedir="." default="clean">
	<property name="gameserver" location="." />
	<!--项目lib路径-->
	<property name="srcLib" location="../Libs/libs" />
	<!--项目config路径-->
	<property name="srcPath1" location="${gameserver}/config" />
	<property name="srcPath2" location="${gameserver}/game-config" />
	<!--指定 ant 生成的路径-->
	<property name="buildPath" value="${basedir}/build" />
	<!--项目编译路径-->
	<property name="compliePath" value="${buildPath}/classes" />
	<!--lib拷贝路径-->
	<property name="lib" value="${buildPath}/lib" />
	<!--dbversion拷贝路径-->
	<property name="srcDBPath" value="${gameserver}/dbversion" />
	
	<!--最终生成位置-->
	<property name="targetPath" value="../project/" />
	<property name="configPath1" location="${targetPath}/config" />
	<property name="configPath2" location="${targetPath}/game-config" />
	<property name="libPath" location="${targetPath}/lib" description="所需lib包"/>
	<property name="dbPath" location="${targetPath}/dbversion" />

	<target name="buildCore" description="先更新core">
		<ant antfile="build.xml" dir="../GameCore" inheritall="false" inheritrefs="false" />
	</target>
	
	<target name="init" description="初始化">
		<echo message="初始化" />
		<echo message="JDK版本号:${ant.java.version}"/>
		<mkdir dir="${compliePath}" />
		<mkdir dir="${buildPath}" />
		<mkdir dir="./build/lib" />
		<copy todir="${lib}">
			<fileset dir="${srcLib}" />
		</copy>
		<copy todir="${libPath}">
			<fileset dir="${srcLib}" />
		</copy>
		<copy todir="${configPath1}">
			<fileset dir="${srcPath1}" />
		</copy>
		<copy todir="${configPath2}">
			<fileset dir="${srcPath2}" />
		</copy>
		<copy todir="${dbPath}">
			<fileset dir="${srcDBPath}" />
		</copy>
		<!--拷贝xml文件-->
		<copy todir="${buildPath}/classes">
			<fileset dir="${gameserver}/src">
			    <exclude name="**/*.java"/>
			</fileset>
		</copy>
	</target>

	<target name="complie" depends="init" description="编译">
		<echo message="开始编译" />
		<!--destdir:编译好的文件存放位置-->
		<javac srcdir="${gameserver}" destdir="${compliePath}" encoding="UTF-8" includeantruntime="false" debug="on">
			<classpath>
				<fileset dir="${lib}">
					<include name="*.jar" />
				</fileset>
			</classpath>
		</javac>
	</target>

	<!--打包-->
	<target name="build" depends="complie" description="打包">
		<echo message="打包" />
		<!--引入lib包-->
		<!--对目录进行组合,pathsep为分隔符-->
		<pathconvert property="libs.project" pathsep=" ">
			<!--对路径组合方式进行控制-->
			<mapper>
				<!--联合多个mapper-->
				<chainedmapper>
					<!--过滤文件,将路径去掉,只保留文件名-->
					<flattenmapper />
					<!--过滤+转换器,将所有文件名前面加上lib,
							lib/*将jar包与路径组合-->
					<globmapper from="*" to="lib/*" />
				</chainedmapper>
			</mapper>
			<!--最后指定影响的文件 -->
			<fileset dir="${buildPath}">
			 	<include name="**/*.jar" />
			</fileset>
		</pathconvert>

		<!--为jar包指定manifast-->
		<jar jarfile="${targetPath}/${ant.project.name}.jar" >
			<manifest>
				<attribute name="Main-Class" value="GameStart" />
				<attribute name="Class-Path" value="${libs.project}" />
			</manifest>
			<fileset dir="${compliePath}" includes="**/*"/>
			<fileset dir="./src" includes="dbcp.properties"/>
			<fileset dir="./src" includes="message.xml"/>
			<fileset dir="./src" includes="log4j2.xml"/>
		</jar>
	</target>

	<target name="clean" depends="build">
		<delete failonerror="false" includeemptydirs="true">
			<fileset dir="${buildPath}"/>
		</delete>
	</target>
</project>

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值