使用ant編譯helloworld.java的執行個體

來源:互聯網
上載者:User

1.建立一個ant 項目目錄結構: 
  /home/nh/helloworld   :項目主目錄 
              /src   :來源程式目錄 
              /classes   :編譯後的   class   檔案目錄 
              /lib   :開發項目所需要的類庫目錄,比如開發資料庫時所需要的   jdbc   lib(這次沒用到) 
              /jar   :打包好的   jar   程式目錄(這次沒用到) 
              /build.xml   :項目設定檔 

build.xml內容如下:  

<?xml version="1.0" encoding="UTF-8" ?>

<project default="build" basedir=".">
   
    <property name="appname" value="helloworld" />
    <property name="base" value="." />
    <property name="src" value="src" />
    <property name="build" value="classes" />
    <property name="myclasspath" value="${build}" />
   




    <target name="build">
           <mkdir dir="${build}" />
           <javac classpath="$myclasspath" srcdir="${src}" destdir="${build}">
                 <include name="helloworld.java" />
           </javac>
    </target>




   <target name="run" depends="build">
       <exec executable="java">
          <arg line=" -classpath ${myclasspath} helloworld" />
       </exec>
   </target>




   <target name="clean">
       <delete includeEmptyDirs="true">
           <fileset dir="${build}"/>
       </delete>
   </target>

</project>



2.建立   helloworld.java 

/home/nh/helloword/src/helloworld.java ,源碼如下:
----------------------------------------------------------------------------- 
/** 
*   Demo   class   for   run   HelloWorld   by   ANT 
*/ 

public   class   HelloWorld   { 
      public   static   void   main(String   args[]){ 
              System.out.println   ( "Hello   World! "); 
      } 
}   //EOC 
----------------------------------------------------------------------------- 

3.編譯   helloworld .java
nh@57ubuntu:~/helloworld$ ant build
Buildfile: build.xml
build:
    [javac] Compiling 1 source file to /home/nh/helloworld/classes
BUILD SUCCESSFUL
Total time: 1 second

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.