在Eclipse下使用ant

來源:互聯網
上載者:User

標籤:des   style   blog   http   java   color   

目前的Eclipse都整合了ant,但是如何在Eclipse下使用ant呢?

1.建立Java Project-建立Java檔案HelloWorld.java

HelloWorld.java:

package example;public class HelloWorld {    public static void main(String[] args) {       System.out.println("Hello World");    }}
View Code

2.在工程根目錄下建立build.xml

build.xml:

<?xml version="1.0" encoding="utf-8"?><project default="main" basedir=".">    <target name="main" depends="compile, compress" description="Main target">       <echo>Building the .jar file.</echo>    </target>    <target name="compile" description="Compilation target">       <javac srcdir="${basedir}/src/example" />    </target>    <target name="compress" description="Compression target">       <jar jarfile="HelloWorld.jar" basedir="${basedir}/src/example"includes="*.class" />    </target></project>
View Code

此指令檔內容是編譯/src/example下的java檔案,並就地產生class檔案,將這個class檔案打成jar包,HelloWorld.jar。

此時工程的目錄結構如所示:

右鍵選中HelloAnt工程,選擇Properties:

選擇Builders-New…,選擇Ant Build,

Name:Ant_Builder;

Buildfile:${workspace_loc:/HelloAnt/build.xml};

Base Directory:${workspace_loc:/HelloAnt};

(按“Browse Workspace”選擇工程根目錄)

 

在Builder面板中鉤上Ant_Build,去掉Java Builder,即可編譯執行。

每次編譯時間,右鍵build.xml,選擇Run As-Ant Build:

編譯結果:

Buildfile: F:\workfile\ant_test\build.xmlcompile:    [javac] F:\workfile\ant_test\build.xml:7: warning: ‘includeantruntime‘ was not set, defaulting to build.sysclasspath=last; set to false for repeatable buildscompress:main:     [echo] Building the .jar file.BUILD SUCCESSFULTotal time: 1 second
View Code
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.