在Eclipse上使用Ant发布项目

这里笔者使用是Eclipse3.7,但相信其他的Eclipse的使用方法也是一致的。

如图,我们先右键增加一个文件。

文件名取名为build.xml ,这里是固定,Eclipse只认这个名字。

build.xml的内容如下:

<?xml version="1.0"?>
<project name="bbs" default="deploy" basedir=".">
	
	<property file="build.properties" />
	<property name="resin.home" value="D:\resin\resin-3.2.0"/>
	<property name="lib.dir"    value="${basedir}/WebContent/WEB-INF/lib"/>
	
	<path id="compile.classpath">   
	    <fileset dir="${resin.home}/lib">
	        <include name="*.jar"/>   
	    </fileset>
	    <fileset dir="${lib.dir}">   
	        <include name="*.jar"/>   
	    </fileset>   
	</path>
	
	<target name="copyProperties">
		
		<copy todir="${dist}/WEB-INF/classes">
			<fileset dir="src/java">
				<include name="*.properties"/>
			</fileset>
		</copy>
	</target>
	
	<target name="compile"  depends="copyProperties">
		<javac srcdir="src/java" destdir="${dist}/WEB-INF/classes/" includeantruntime="on">
			<classpath refid="compile.classpath"></classpath>
		</javac>
	</target>
	
    <target name="deploy" depends="compile">
        
    	<copy  todir="${dist}">
        	<fileset dir="WebContent"></fileset>
        </copy>
    	
    	<copy tofile="${dist}/WEB-INF/classes/oa.properties" overwrite="true">
    	    <fileset file="src/config/oa_${company}.properties"></fileset>
    	</copy>
    	
    </target>
</project>

然后,我们再增加一个build.properties的配置文件,把一些属性写在配置文件中:

build.properties的内容如下:

dist=D:/resin/resin-3.2.0/webapps/oa

然后,右键点击build.xml文件,

最后Run一下就可以跑Ant脚本了。

猜你喜欢

转载自tntxia.iteye.com/blog/2249771