<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    2006-6-24

    Installing Ant
    The binary distribution of Ant consists of the following directory layout:

      ant
       +--- bin  // contains launcher scripts
       |
       +--- lib  // contains Ant jars plus necessary dependencies
       |
       +--- docs // contains documentation
       |      +--- ant2    // a brief description of ant2 requirements
       |      |
       |      +--- images  // various logos for html documentation
       |      |
       |      +--- manual  // Ant documentation (a must read ;-)
       |
       +--- etc // contains xsl goodies to:
                //   - create an enhanced report from xml output of various tasks.
                //   - migrate your build files and get rid of 'deprecated' warning
                //   - ... and more ;-)

    Only the bin and lib directories are required to run Ant. To install Ant, choose a directory and copy the distribution file there. This directory will be known as ANT_HOME.
    在安裝ant的時候,需要兩個環境變量。ANT_HOME指定ant的安裝目錄,Path指定bin的目錄路徑。
    -------------------------------------

    Using Ant
    Each Buildfile contains one project and at least one (default) target. Targets contain task elements. Each task element of the buildfile can have an id attribute and can later be referred to by the value supplied to this.

    A project has three attributes: name (required no), default(the default target to use when no target is supplied) (required no), basedir (required no).
    Optionally, a description for the project can be provided as a top-level <description> element. It is include in the output of the ant - projecthelp command. The description has no parameters. One example:
    <description>
    This buildfile is used to build the Foo subproject within
    the large, complex Bar project.
    </description>

    Each project defines one or more targets. A target is a set of tasks you want to be executed. When starting Ant, you can select which target(s) you want to have executed.
    A target has the following attributes: name (required yes), depends, if, unless, description.

    A task is a piece of code that can be executed.
    Tasks have a common structure:
    <name attribute1="value1" attribute2="value2" ... />

    Example Buildfile
    <project name="MyProject" default="dist" basedir=".">
        <description>
            simple example build file
        </description>
      <!-- set global properties for this build -->
      <property name="src" location="src"/>
      <property name="build" location="build"/>
      <property name="dist"  location="dist"/>

      <target name="init">
        <!-- Create the time stamp -->
        <tstamp/>
        <!-- Create the build directory structure used by compile -->
        <mkdir dir="${build}"/>
      </target>

      <target name="compile" depends="init"
            description="compile the source " >
        <!-- Compile the java code from ${src} into ${build} -->
        <javac srcdir="${src}" destdir="${build}"/>
      </target>

      <target name="dist" depends="compile"
            description="generate the distribution" >
        <!-- Create the distribution directory -->
        <mkdir dir="${dist}/lib"/>

        <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
        <jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/>
      </target>

      <target name="clean"
            description="clean up" >
        <!-- Delete the ${build} and ${dist} directory trees -->
        <delete dir="${build}"/>
        <delete dir="${dist}"/>
      </target>
    </project>
    --------------------------------------

    Running Ant
    Examples
    ant
    runs Ant using the build.xml file in the current directory, on the default target.

    ant -buildfile test.xml
    runs Ant using the test.xml file in the current directory, on the default target.

    ant -buildfile test.xml dist
    runs Ant using the test.xml file in the current directory, on the target called dist.
    -------------------------------------------

    上面的內容都是從manual中copy出來的,覺得我用到的特征應該不多。會按裝、會寫簡單的build.xml、以及運行ant就可以了。Ant提供的tasks很多,可能大部分都是復雜工程當中所需的,但是對于我個人寫的小projiect,這些tasks就顯得沒有必要了。簡單是一種美德:-),這也是懶得借口之一。
    --------------------------------------------

    Developing with Ant
    Tutorials
    Hello World with Ant

    We want to separate the source from the generated files, so our java source files will be in src folder. All generated files should be under build, and there splitted into several subdirectories for the individual steps: classes for our compiled files and jar for our own JAR-file.
    The later directories are created by our buildfile, so we have to create only the src directory.
    write this code into src/oata/HelloWorld.java 代碼如下:
      package oata;
      public class HelloWorld {
          public static void main(String[] args) {
              System.out.println("Hello World");
          }
      }

    The most simplest buildfile describing that would be:寫一個最簡單的build.xml:
    <project>

        <target name="clean">
            <delete dir="build"/>
        </target>

        <target name="compile">
            <mkdir dir="build/classes"/>
            <javac srcdir="src" destdir="build/classes"/>
        </target>

        <target name="jar">
            <mkdir dir="build/jar"/>
            <jar destfile="build/jar/HelloWorld.jar" basedir="build/classes">
                <manifest>
                    <attribute name="Main-Class" value="oata.HelloWorld"/>
                </manifest>
            </jar>
        </target>

        <target name="run">
            <java jar="build/jar/HelloWorld.jar" fork="true"/>
        </target>

    </project>

    Now you can compile, package and run the application via

    ant compile
    ant jar
    ant run

    Or shorter with

    ant compile jar run

    完善build file:
    <project name="HelloWorld" basedir="." default="main">

        <property name="src.dir"     value="src"/>

        <property name="build.dir"   value="build"/>
        <property name="classes.dir" value="${build.dir}/classes"/>
        <property name="jar.dir"     value="${build.dir}/jar"/>

        <property name="main-class"  value="oata.HelloWorld"/>

        <target name="clean">
            <delete dir="${build.dir}"/>
        </target>

        <target name="compile">
            <mkdir dir="${classes.dir}"/>
            <javac srcdir="${src.dir}" destdir="${classes.dir}"/>
        </target>

        <target name="jar" depends="compile">
            <mkdir dir="${jar.dir}"/>
            <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
                <manifest>
                    <attribute name="Main-Class" value="${main-class}"/>
                </manifest>
            </jar>
        </target>

        <target name="run" depends="jar">
            <java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>
        </target>

        <target name="clean-build" depends="clean,jar"/>

        <target name="main" depends="clean,run"/>

    </project>

    Now it's easier, just do a ant and you will get

    Buildfile: build.xml

    clean:

    compile:
        [mkdir] Created dir: C:\...\build\classes
        [javac] Compiling 1 source file to C:\...\build\classes

    jar:
        [mkdir] Created dir: C:\...\build\jar
          [jar] Building jar: C:\...\build\jar\HelloWorld.jar

    run:
         [java] Hello World

    main:

    BUILD SUCCESSFUL

    ========這下面是我嘗試了這例子后在cmd中的輸出==========
    Microsoft Windows XP [版本 5.1.2600]
    (C) 版權所有 1985-2001 Microsoft Corp.

    D:\doctemp\project helloworld using ant>ant
    Buildfile: build.xml

    clean:
       [delete] Deleting directory D:\doctemp\project helloworld using ant\build

    compile:
        [mkdir] Created dir: D:\doctemp\project helloworld using ant\build\classes
        [javac] Compiling 1 source file to D:\doctemp\project helloworld using ant\b
    uild\classes

    jar:
        [mkdir] Created dir: D:\doctemp\project helloworld using ant\build\jar
          [jar] Building jar: D:\doctemp\project helloworld using ant\build\jar\Hell
    oWorld.jar

    run:
         [java] Hello World

    main:

    BUILD SUCCESSFUL
    Total time: 2 seconds
    D:\doctemp\project helloworld using ant>

    =====================================================

    此后還講了使用外部libraries的例子,這里省去。

     

    posted @ 2006-06-26 01:27 cjren 閱讀(714) | 評論 (0)編輯 收藏
     

    2006-6-24
    小敘
    之前寫很小的程序的時候,幾個源文件和編譯后的class文件統一都放在同一個目錄之下,倒也相安無事而且省事。但是在做畢設(坦克對戰游戲)的時候,多則二十個的源文件,再連同那些class文件都放在一個目錄下,顯得非常的雜亂。于是覺得是時候考慮一下一個project的目錄結構了,例如把源文件和class文件分開,把測試文件也統一在另一個獨立的目錄下。

    回顧和插曲
    之前用C語言程序學習編寫小的編譯器的時候,我就曾不解怎么把一個程序分為幾個獨立的文件。那時的做法很傻但簡單,就是盡量不用.h頭文件,只使用.c文件,然后一層一層的include。后來看《The C Programming Language》第四章head files,才較為清楚地知道了怎樣通過.h文件來把一個程序分割為幾個小的源代碼文件。
    這里有一個小的插曲,在3月末的研究生復式中,其中一道編程題是實現stack數據結構,提供push,pop和get的函數實現,并提供一到兩個測試例子。我是用C實現的,在實現過程中分為了三個文件,其中兩個.c文件和一個.h文件。分別是main.c stack.c and stack.h。
    stack.h:定義了main.c and stack.c公用的stack struct變量,以及對main.c將需要用到的和在stack.c里由于函數定義順序的關系需要到的函數進行了聲明(區別于定義)。
    stack.c:include “stack.h”,定義了一系列函數,可以為其它文件中所調用(這也是為什么這當中的一些函數需要在stack.h中聲明的原因)。
    main.c:include “stack.h”,使用到了stack.c中的函數,也就是執行了兩個測試例子而已。
    stack的具體操作實現細節這個略過了。考試的結果得了A,想必這種源代碼文件的組合關系也另評分的老師覺得清晰和有序:-)

    原則
    這方面的工具(build tool: 名字是構建工具)最流行的好像是ant,在看《Developing Games in Java》的時候,作者也是通過提供build.xml給ant來完成相應的工作,于是我嘗試把build.xml看明白了之后,第一印象就是它可以很好的處理一個project的各種文件的目錄結構:-),第二印象是又得使用不熟悉的工具了:-(。我覺得自己很懶,懶在不想學一些可能使用不多或不大有用的工具,同時覺得怕,怕在于這個ant是人家的,我害怕一個東西以我不清楚的方法和細節完成工作。這涉及一個學習新工具時候的原則問題:一,它好用嗎,可以meet my need嗎;二,它是怎么完成的啊,我想“看”清楚它的做法;三,夠簡單嗎。
    ant是一個現成的魔術,而我希望自己可以使用現掌握的簡單的知識做一個最簡單的而且合乎我要求的魔術,而最要緊的是我知道它到底做了什么,它是怎么做了。

    工作
    現在我有必要自己來完成兩件事情:一:明確在一個project目錄下有什么目錄;二,我怎么實現把各種文件(如.java, .class, .jar, .html)存放到相應的目錄并且讓它們和調的協作呢?我現在只懂編譯時候的-d參數和運行時候的-cp參數。

    (1)
    嘗試學習ant的最簡的使用方法,記錄在"mynotes about ant -ant的最簡單使用方法.txt"文件中。
    (2)
    下面嘗試自己來構建目錄結構,而不使用ant。記錄在"2006-06-24build project.doc"文件中。


    ----------------------------
    附錄一:bat批處理文件中常用的命令
    date /t
    time /t

    mkdir or md
    del /Q or earse /Q
    rmdir or rd

    echo
    @echo off
    rem
    pause

    date /t > a.txt | type a.txt //間接地建立一個a.txt文件并把文件的內容顯示出來

    posted @ 2006-06-26 01:25 cjren 閱讀(350) | 評論 (0)編輯 收藏
     
    最近完成了畢設和答辯,畢設的主要內容是(1)做一個單機版的坦克游戲,(2)在此基礎上嘗試加入聯網操控和聊天功能。

    單機版的特點:title-based map,雙人對戰,自定義地圖
    r_tankbattle-1.PNG

    提供給玩家使用的地圖編輯器:
    mapeditor1.PNG

    posted @ 2006-06-24 00:13 cjren 閱讀(1041) | 評論 (8)編輯 收藏
     
    ??????? 還有一個禮拜就畢業回廣東了,但是離研一的開學時間還有兩個多月,現在正在找廣州和佛山地區的實習機會。
    ??????? 實習工作希望和軟件開發有關的,但也不是硬性一定要跟計算機有關。實習嘛,為了鍛煉和學習平時學校里沒有的東西而已。
    posted @ 2006-06-23 21:50 cjren 閱讀(197) | 評論 (0)編輯 收藏
    僅列出標題
    共2頁: 上一頁 1 2 
     
    主站蜘蛛池模板: 国产精品免费久久久久电影网| 免费人成在线观看视频播放| 国产免费人成视频尤勿视频| 亚洲一日韩欧美中文字幕在线| 久久精品国产亚洲av四虎| 亚洲精品和日本精品| 18禁成年无码免费网站无遮挡| 一级毛片免费视频| 免费无码又爽又刺激网站| 国产AV日韩A∨亚洲AV电影| 亚洲欧美日韩国产精品一区| 亚洲精品一区二区三区四区乱码 | 国产在线观看免费完整版中文版| 18禁无遮挡无码国产免费网站| 国产99视频精品免费视频76| 久久久亚洲精华液精华液精华液 | 歪歪漫画在线观看官网免费阅读| 毛片免费在线观看| 你懂的网址免费国产| 一区免费在线观看| 免费一级毛片在线播放视频免费观看永久| 亚洲人成人网毛片在线播放| 亚洲人成免费网站| 亚洲熟妇无码久久精品| 亚洲精品午夜视频| 亚洲AV成人噜噜无码网站| 亚洲色图黄色小说| 亚洲国产精品不卡在线电影| 亚洲成色在线综合网站 | 99在线免费观看视频| 爽爽爽爽爽爽爽成人免费观看| 一级毛片aa高清免费观看| 美国毛片亚洲社区在线观看| 亚洲精品国产精品| 亚洲爆乳AAA无码专区| 老子影院午夜伦不卡亚洲| 国产成人亚洲综合在线| 免费播放美女一级毛片| 又硬又粗又长又爽免费看 | 亚洲午夜久久久影院| 国外亚洲成AV人片在线观看|