1. 程式人生 > >Ant在eclipse中搭建專案

Ant在eclipse中搭建專案

後新建一個 HelloWorld 類,我們下面就是將這個專案通過 Ant 來編譯,打包,類的程式碼列表如清單 1 所示:

package java;

public class Helloworld {
	public String sayHellow(String name){
		return "Hello"+name;
	}
}

然後再新建一個 build 檔案,命名為 build.xml:
 <?xml version="1.0" encoding="UTF-8"?> 
 <project name="project" default="default"> 
    <target name="default" depends="depends" description="description"> 
        <javac srcdir="src" destdir="bin" includes="org/**"  includeantruntime="true"></javac> 
    	 <jar basedir="bin" destfile="dist/ant_project.jar"></jar> 
    	 <war destfile="dist/ant_project.war" webxml="WEB-INF/web.xml"> 
    		 <classes dir="bin"></classes> 
    	 </war> 
    </target> 
    <target name="depends"> 
    </target> 
 </project>

2、運用ant

(1)eclipse-右鍵專案-properties-Builders-Add buids(選擇 ant builder):

(2)Buildfile-點選選擇專案下的build.xml檔案,生成路徑為:${workspace_loc:/ant_project/build.xml}

Base directory-點選選擇專案名字,生成路徑為:

${workspace_loc:/ant_project}

(3)當前頁面切換到classPath下,add jar(junit.jar,這個jar之前先放在ant_project下面)

(4)去掉Java builder勾選,選擇ant builder

(5)點選build.xml右鍵---run as ----ant build 開始執行ant命令,構建ant專案以及打包工作。


參考:http://blog.csdn.net/qing419925094/article/details/42968007