2016-03-03 69 views
0

我在eclipse中實現了一個簡單的遊戲。它由大約8個類組成。 這是我的學校作業。需要爲eclipse項目製作一個ant build文件

在規範的轉向中,寫有: 「向我發送所有源代碼,文檔和ant編譯文件,它允許編譯項目並生成javadoc文檔」。

我真的不明白螞蟻是如何工作的。我搜索了一些教程,但我也無法理解它們。我試圖在eclipse中生成build.xml文件,但老師說這也不起作用。

有人可以給我一些簡單的步驟或給我鏈接到一些真正的基本教程嗎?感謝幫助。

這是eclipse生成的ant(導出項目爲antbuildfile): 它有點奇怪,因爲我很久以前刪除了BasicPaint類。

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
    <!-- WARNING: Eclipse auto-generated file. 
       Any modifications will be overwritten. 
      To include a user specific buildfile here, simply create one in the same 
      directory with the processing instruction <?eclipse.ant.import?> 
      as the first entry and export the buildfile again. --><project basedir="." default="build" name="Snakes_and_Adders"> 
<property environment="env"/> 
<property name="debuglevel" value="source,lines,vars"/> 
<property name="target" value="1.8"/> 
<property name="source" value="1.8"/> 
<path id="Snakes_and_Adders.classpath"> 
    <pathelement location="bin"/> 
</path> 
<target name="init"> 
    <mkdir dir="bin"/> 
    <copy includeemptydirs="false" todir="bin"> 
     <fileset dir="src"> 
      <exclude name="**/*.java"/> 
     </fileset> 
    </copy> 
</target> 
<target name="clean"> 
    <delete dir="bin"/> 
</target> 
<target depends="clean" name="cleanall"/> 
<target depends="build-subprojects,build-project" name="build"/> 
<target name="build-subprojects"/> 
<target depends="init" name="build-project"> 
    <echo message="${ant.project.name}: ${ant.file}"/> 
    <javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}"> 
     <src path="src"/> 
     <classpath refid="Snakes_and_Adders.classpath"/> 
    </javac> 
</target> 
<target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/> 
<target name="BasicPaint"> 
    <java classname="snakes_and_adders.BasicPaint" failonerror="true" fork="yes"> 
     <classpath refid="Snakes_and_Adders.classpath"/> 
    </java> 
</target> 
<target name="Game"> 
    <java classname="snakes_and_adders.Game" failonerror="true" fork="yes"> 
     <classpath refid="Snakes_and_Adders.classpath"/> 
    </java> 
</target> 
<target name="NewGame"> 
    <java classname="snakes_and_adders.NewGame" failonerror="true" fork="yes"> 
     <classpath refid="Snakes_and_Adders.classpath"/> 
    </java> 
</target> 
<target name="PaintingExample"> 
    <java classname="snakes_and_adders.PaintingExample" failonerror="true" fork="yes"> 
     <classpath refid="Snakes_and_Adders.classpath"/> 
    </java> 
</target> 

+0

請發佈您的「非工作」ant文件,爲什麼它不工作。另外,請查看[基本ant例子](https://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html)。 – f1sh

回答

1

螞蟻被用來執行那些來構建應用程序有用的任務。你有像<javac><jar>等任務。編譯你的類,並把它們放入一個jar文件。

我不明白爲什麼build.xml生成的文件不起作用。但你可以把它當作一個例子來理解ant如何工作。您也可以調整該build.xml文件以使其可以在任何地方工作。

本教程第一眼看起來很好的解釋:http://www.javaworld.com/article/2076208/java-app-dev/automate-your-build-process-using-java-and-ant.html

我發現,螞蟻可以很容易地複雜,它會帶你時間去了解它很好,但它確實是可行的。

相關問題