Eclipse创建ant脚本文件

1. 在项目根目录下新建一个build.xml文件。

2. 编辑该文件

加入:

<?xml version="1.0" encoding="UTF-8"?>
  <!-- Basedir is the relative path of project root folder based on the location of the build.xml -->
  <project name="[Project name]" default="init" description="[Project description]" basedir=".">
	<property name="src.dir" value="${basedir}\src" />
	<property environment="env" />
	<property name="build.dir" value="${basedir}\build" />
	<property name="output.dir" value="${basedir}\output" />
	
	<path id="build.classpath">
		<fileset dir="${basedir}/lib">
			<include name="*.jar" />
		</fileset>
	</path>
	
	<target name="prepare">
		<delete dir="${build.dir}" />
		<mkdir dir="${build.dir}" />
	</target>

	<target name="compile" depends="prepare" description="compile">
		<javac srcdir="${src.dir}" destdir="${build.dir}">
			<classpath refid="build.classpath" />
			<!-- The dependent classes generated in other project -->
			<classpath location="D:/My Documents/spring_learn/utilities/build/classes" />
		</javac>
	</target>

	<target name="package" depends="compile" description="Compile source code">
		<mkdir dir="${build.dir}/lib"/>
		<copy todir="${build.dir}/lib">
			<fileset dir="${basedir}/lib">
				<include name="commons-codec-1.6.jar" />
			</fileset>
		</copy>
		<mkdir dir="${output.dir}"/>
		<jar update="true" compress="true" jarfile="${output.dir}/${ant.project.name}.jar">
		<!-- The key-value pairs defined in the MANIFEST.MF file -->
		<manifest>
	    	    <attribute name="Main-Class" value="com.john.encryption.gui.MainFrame"/>
	    	    <attribute name="Class-Path" value=". commons-codec-1.6.jar"/>
	    	</manifest>
 	    	<metainf dir="${srcDir}/META-INF/">
 	        	<include name="**/*.xml" />
 	    	</metainf>
			<fileset dir="${build.dir}">
				<include name="**/loader/*.class" />
				<include name="**/encryption/**/*.class" />
				<include name="**/*.jar" />
				<exclude name="**/SwingDragDrop*.class" />
				<exclude name="**/ProgressBarDemo*.class" />
			</fileset>
		</jar>
	</target>
	
	<target name="deploy" depends="compile" description="deploy">
		<copy file="${basedir}\${ant.project.name}.jar" todir="${jboss.home}\server\${jboss.server.config}\deploy" />
	</target>
	
	<target name="undeploy" description="undeploy">
		<delete file="${jboss.home}\server\${jboss.server.config}\deploy\${ant.project.name}.jar" />
	</target>
</project>


3. 在编辑区右键,选择[Run as] - [Ant Build],即可运行ant脚本。

你可能感兴趣的:(eclipse,xml,ant,Build)