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

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

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

    2006年6月26日

    http://www.csit.fsu.edu/~burkardt/data/data.html
    可以從中找到大部分文件格式的相關信息。例如BMP,Obj等等。

    http://www.csit.fsu.edu/~burkardt/data/obj/obj.html
    介紹OBJ文件格式,關鍵是當中提供了讀寫和轉換OBJ文件的工具建議。

    posted @ 2006-10-31 00:11 cjren 閱讀(272) | 評論 (0)編輯 收藏
     

    ?helloWorldEg.jpg
    就一幅圖,仔細看看和聯(lián)想一下,也許會有點得益:-)

    posted @ 2006-07-23 20:14 cjren 閱讀(268) | 評論 (0)編輯 收藏
     
    What do you know The Life Cycle of a Thread?
    threads-states.gif
    Can you say something about the life cycle of a thread, it's creating, starting, running, not runnale, and stopping? If you do want to know about more, please check it out: http://java.sun.com/docs/books/tutorial/essential/threads/lifecycle.html
    posted @ 2006-07-23 20:10 cjren 閱讀(323) | 評論 (0)編輯 收藏
     

    (1)
    The Art of Programming Language
    《計算機程序設計藝術》 清華大學出版社

    (2)
    Introduction to Algorithms, Second Edition
    Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein
    MIT
    《算法導論,影印版》高等教育出版社

    (3)
    Intruduction to The Design and Analysis of Algorithms
    (US)Anany Levitin
    算法設計與分析基礎
    潘彥 譯?
    清華大學出版社

    其實第一本我沒有看過,只是提及算法方面的書籍,這一本好像都應該為人所知道似的。第二本的課程資料可以在mit的open course ware頁面下載。第三本的譯本很不錯,感覺很有點幽默有趣,而且書的結構挺新穎,不至于讓人馬上對算法這東西覺得恐怖和煩悶。推薦第三本。

    posted @ 2006-07-23 19:38 cjren 閱讀(739) | 評論 (0)編輯 收藏
     

    移動 -- 只有GSM,GPRS是GSM的升級版,134-139 手機使用移動的SIM卡???????

    聯(lián)通 -- GSM? 130,131,132?????? 手機使用聯(lián)通SIM卡
    ?????????-- CDMA 133 (聯(lián)通新時空),手機使用UIM卡


    GSM比較簡單。所謂的GSM 900/1800/1900是指GSM手機的工作頻率,分別是中國移動支持的900MHz,1900MHz和美國常用的1900MHz。在國內用支持900MHz和1800MHz的GSM 900/1800雙頻手機就可以了。如果要出國到美國用的,就要用支持1900MHz的三頻手機了。

    CDMA比GSM的通話質量、手機輻射小和保密性方面都好,但是技術!=市場。
    CDMA -- CDMA800
    ?????????? ?-- CDMA 1X 現(xiàn)在聯(lián)通CDMA網(wǎng)絡所采取的技術。與真正的CDMA2000相比,CDMA 1x就像我剛才說的,只能支持到153.6kbps的數(shù)據(jù)速度,因此被稱為是2.5G的技術,還不是真正3G的技術。
    ????????? ? -- CDMA2000 一種3G的標準。


    3G 有三個標準
    ??????????? -- WCDMA 有利于中國移動,設備由歐洲進口,容易升級到WCDMA。這套系統(tǒng)能夠架設在現(xiàn)有的GSM網(wǎng)絡上,對于系統(tǒng)提供商而言可以較輕易地過渡,而GSM系統(tǒng)相當普及的亞洲對這套新技術的接受度預料會相當高。因此W-CDMA具有先天的市場優(yōu)勢。
    ?
    ???????????? -- CDMA2000 利于聯(lián)通,設備由美國進口,容易升級到CDMA2000。目前使用CDMA的地區(qū)只有日、韓和北美,所以CDMA2000的支持者不如W-CDMA多。不過CDMA2000的研發(fā)技術卻是目前各標準中進度最快的,許多3G手機已經(jīng)率先面世。

    ???????????? -- TD-SCDMA 中國自己有獨立知識產(chǎn)權的產(chǎn)品。采用這一標準,對于國防等重要領域國民經(jīng)濟安全有利。據(jù)說中國電信和中國網(wǎng)通都在申請移動運營牌照,他們傾向于TDS-CDMA。
    ?????? 至于現(xiàn)在中國采用哪一種現(xiàn)在還沒有定論。畢竟需要市場和企業(yè)來最終決定,記住技術優(yōu)秀的并不代表最終就能勝出。

    posted @ 2006-07-23 19:28 cjren 閱讀(550) | 評論 (0)編輯 收藏
     

    "Computer science is no more about computers than astronomy is about telescopes."

    ????????????????????????????????????????????????? E. W. Dijkstra
    計算機是一個工具,一個人造的工具,人制造工具的目的是什么?協(xié)助自己完成生產(chǎn)勞動,或確切地說是完成自己生存和生活的需要。由于需要完成大量的運算而產(chǎn)生的計算機,即使是到現(xiàn)在也局限于信息的處理,包括簡單的運算和信息(數(shù)字)的存儲。

    而在學習當中,“sprint,struct”等這些名字聽起來真的很大,而我常問自己“我需要學習它嗎?”。是否不懂它們就不算懂java了呢?我從4月份開始覺得java離自己越來越遠了,因為我上許多的關于java的論壇,看到的極大部分都是討論框架,而我對此沒有什么概念。“需求驅動學習”是我的信條,沒有這個需求,你就沒有學習那相應知識的必要,更沒有動力。也許這是我懶的借口:-) 大概是自己尚且是學生,沒有投身都企業(yè)生產(chǎn)當中因此對這些企業(yè)開發(fā)的知識沒有概念吧。反正覺得現(xiàn)在沒有學這個的必要,誰知道兩年后是否有什么summer or XXname的框架出現(xiàn)呢?

    這個暑假其實自己還是想把握時間看看書的,反正又沒有找到實習工作。例如data structure & algorithm,算法分析這門課沒有學過,真的遺憾,只能自己補補;還有那Developing Games in Java的part 3,當中講的是3d的renderring,而不涉及opengl以及java3d或opengl binding等API,自己還是很有興趣的。而昨天在國外的大學的網(wǎng)站上下載了一個OS課程的lecture notes,正好復習一下操作系統(tǒng)的概念。

    posted @ 2006-07-08 10:25 cjren 閱讀(649) | 評論 (1)編輯 收藏
     
         摘要: 2006-7-7 CP2003 -- Principles of Programming Languages 1997 This course (subject) comes frome http://www.cs.jcu.edu.au/Subjects/cp2003/1997/lecturenotes.html, and you can fin...  閱讀全文
    posted @ 2006-07-07 10:49 cjren 閱讀(614) | 評論 (0)編輯 收藏
     

    上午看某文章時候涉及緩沖區(qū)溢出的問題,談到C的棧和堆,有所不懂于是baidu了一下發(fā)現(xiàn)論壇上的解釋都較為凌亂,google一下后發(fā)現(xiàn)國外大學的Lecture Notes 中有不少的說明,下面簡單的摘錄三段,一是c中的,二是對于java的,三是從os角度看的。

    Stack vs Heap Allocation
    How the memory of the computer is organized for a running program? When a program is loaded into memory, it is organized into three areas of memory, called segments: the text segment, stack segment, and heap segment. The text segment (sometimes also called the code segment) is where the compiled code of the program itself resides. This is the machine language representation of the program steps to be carried out, including all functions making up the program, both user defined and system.

    The remaining two areas of system memory is where storage may be allocated by the compiler for data storage. The stack is where memory is allocated for automatic variables within functions. A stack is a Last In First Out (LIFO) storage device where new storage is allocated and deallocated at only one ``end'', called the Top of the stack. This can be seen in Figure 14.13.?
    ?figure14.13.gif

    When a program begins executing in the function main(), space is allocated on the stack for all variables declared within main(), as seen in Figure 14.13(a). If main() calls a function, func1(), additional storage is allocated for the variables in func1() at the top of the stack as shown in Figure 14.13(b). Notice that the parameters passed by main() to func1() are also stored on the stack. If func1() were to call any additional functions, storage would be allocated at the new Top of stack as seen in the figure. When func1() returns, storage for its local variables is deallocated, and the Top of the stack returns to to position shown in Figure 14.13(c). If main() were to call another function, storage would be allocated for that function at the Top shown in the figure. As can be seen, the memory allocated in the stack area is used and reused during program execution. It should be clear that memory allocated in this area will contain garbage values left over from previous usage.

    The heap segment provides more stable storage of data for a program; memory allocated in the heap remains in existence for the duration of a program. Therefore, global variables (storage class external), and static variables are allocated on the heap. The memory allocated in the heap area, if initialized to zero at program start, remains zero until the program makes use of it. Thus, the heap area need not contain garbage.
    小結:
    Stack: automatic variables within functions
    Heap: global variables (storage class external), and static variables
    ============================
    In java 情況如下
    (1)
    ?The stack is the program memory area, so all your primitive type variables and the memory adress of your objects are written on the stack. It is a fast access valuable memory area.
    The heap is where the VM keeps the objects, and it is a huge amount of memory. When you create an object, the VM puts the object in the HEAP and puts the adress of the object created on the STACK.
    (2)
    ?There are two kinds of memory used in Java. These are called stack memory and heap memory. Stack memory stores primitive types and the addresses of objects. The object values are stored in heap memory. An object reference on the stack is only an address that refers to the place in heap memory where that object is kept.
    ?It is useful to know that these two different kinds of memory exist in Java. Stack memory is the program's memory, and heap memory resides outside of the program.這好像有點跟C的不同(相反)。
    引入一點垃圾回收機制的知識
    ?When you need a new object, Java allocates the required memory. When you are done with an object, the memory is reclaimed for you automatically via Java's garbage collection facility.
    ?Garbage collection runs as a thread in the background, looking for objects that no longer have a usable reference. When it finds them, it destroys them and reclaims the memory.
    ?The implementation of garbage collection varies between Java Virtual Machines. They generally follow the same process, however. First, the garbage collector gets a snapshot of all running threads and all loaded classes. Then, all objects that are referred to by this thread set are marked as current. The process stops when all objects that it is possible to reach have been marked and the rest have been discarded.
    ?In order to help the Virtual Machine, it is a good idea to remove your references to unneeded objects. This is often done by simply setting your reference to null:
    ?Test t = new Test();
    ?t.someAction();
    ?// all done
    ?t = null;
    小結:
    Stack: Primitive data types(primitive types), the addresses of objects(=references).
    Heap:? objects.

    ===============================================
    從系統(tǒng)的角度看 stack(棧)和heap(堆)
    Dynamic Data Structures: The Heap
    A typical personal computer or workstation today has somewhere between 16 and 64 megabytes of RAM installed. Using a technique called virtual memory, the system can swap pieces of memory on and off the machine's hard disk to create an illusion for the CPU that it has much more memory, for example 200 to 500 megabytes. While this illusion is complete as far as the CPU is concerned, it can sometimes slow things down tremendously from the user's perspective. Despite this drawback, virtual memory is an extremely useful technique for "increasing" the amount of RAM in a machine in an inexpensive way. Let's assume for the sake of this discussion that a typical computer has a total memory space of, for example, 50 megabytes (regardless of whether that memory is implemented in real RAM or in virtual memory).
    The operating system on the machine is in charge of the 50-megabyte memory space. The operating system uses the space in several different ways, as shown here:

    ?c-heap.gif
    The operating system and several applications, along with their global variables and stack spaces, all consume portions of memory. When a program completes execution, it releases its memory for reuse by other programs. Note that part of the memory space remains unused at any given time.

    This is, of course, an idealization, but the basic principles are correct. As you can see, memory holds the executable code for the different applications currently running on the machine, along with the executable code for the operating system itself. Each application has certain global variables associated with it. These variables also consume memory. Finally, each application uses an area of memory called the stack, which holds all local variables and parameters used by any function. The stack also remembers the order in which functions are called so that function returns occur correctly. Each time a function is called, its local variables and parameters are "pushed onto" the stack. When the function returns, these locals and parameters are "popped." Because of this, the size of a program's stack fluctuates constantly as the program is running, but it has some maximum size.

    As a program finishes execution, the operating system unloads it, its globals and its stack space from memory. A new program can make use of that space at a later time. In this way, the memory in a computer system is constantly "recycled" and reused by programs as they execute and complete.

    In general, perhaps 50 percent of the computer's total memory space might be unused at any given moment. The operating system owns and manages the unused memory, and it is collectively known as the heap. The heap is extremely important because it is available for use by applications during execution using the C functions malloc (memory allocate) and free. The heap allows programs to allocate memory exactly when they need it during the execution of a program, rather than pre-allocating it with a specifically-sized array declaration.

    posted @ 2006-07-06 17:30 cjren 閱讀(4429) | 評論 (3)編輯 收藏
     


    在嘗試建立自己的可重用package的時候,對package和import語句做了些試驗,記錄結果如下。

    使用說明:
    (1)對于src\com\cjren\util\ClassA.java這個提供給其他類使用的class.
    package com.cjren.util;
    public class ClassA {
    ? ...
    }
    編譯時:
    javac -d . ClassA.java? // -d . 表示了以當前目錄為package語句生成的相對根目錄。
    結果是在ClassA.java所在的目錄下生成了com.cjren.util包,里面含ClassA.class,這個包可以復制剪貼到其他的地方供其他類使用。
    Notes:
    必須使用"-d .",否則ClassA.class并不會放在com.cjren.util包里面,而是生成在和ClassA.java相同的目錄下。


    (2)對于要使用ClassA的ClassB.java.
    import com.cjren.util.ClassA;
    public class ClassB {
    ? ... // use ClassA here
    }

    To compile: javac ClassB.java
    To run:???? 假設com包放在和ClassB.java的當前目錄
    ??????????? java ClassB???????
    ??????????? // or java -cp . ClassB // here use the "-cp ." as the current directory to find the package com.
    ??????????? 假設com包放在D:\Program Files\Java\mypackages下
    ??????????? java -cp D:\Program Files\Java\mypackages ClassB

    Notes:
    錯誤一:
    package com.cjren.util;
    public class ClassA {
    ? ...
    }
    編譯后直接把com.cjren.util包里面的ClassA.class文件拷貝到和ClassB.java相同的目錄下直接使用,
    public class ClassB {
    ? ... // use ClassA here
    }
    To compile: javac ClassB.java
    錯誤信息是
    "ClassB.java:某一行: 無法訪問 ClassA
    ?錯誤的類文件: .\ClassA.class
    ?類文件包含錯誤的類: com.cjren.util.ClassA
    ?請刪除該文件或確保該文件位于正確的類路徑子目錄中。"
    想一想為什么出錯信息是說:“錯誤的類文件: .\ClassA.class, 類文件包含錯誤的類: com.cjren.util.ClassA”呢?因為"錯誤的類文件: .\ClassA.class"當中包含了"錯誤的類: com.cjren.util.ClassA"這個信息,而這個"com.cjren.util.ClassA"是在ClassA.java中的"package com.cjren.util;"語句所造成的。
    正確的做法是把ClassA.class所在的包整個復制粘貼到ClassB.java所在的目錄下,或者在ClassB.java所在的目錄下人為手動的建立com\cjren\util\目錄,然后直接把ClassA.class文件復制粘貼到此。這暗示了代碼生成的包和手動建立的目錄可能是一樣。
    可見,當ClassA.java的源代碼中含"package com.cjren.util;"語句,則生成com.cjren.util包里面的ClassA.class文件里面應該就也包含了自己這個class文件所屬的包信息,所以這個ClassA.class只能放在這個代碼中已經(jīng)指定的特定包的路徑下使用,而不能把這個ClassA.class獨立出來使用,因為這樣的話將ClassA.class文件屬性中的的包信息不相符。當然當這個ClassA.java沒有顯式地制定package語句信息時候,我懷疑(也覺得應該)是默認在ClassA.class文件當中包含了包的信息就是".",可以理解為默認的加入了"package .;"語句。

    錯誤二:
    public class ClassA {
    ? ...
    }
    編譯后這個ClassA.class文件中含有的包的信息是"."當前目錄就包!
    把這個ClassA.class文件,移到以ClassB.java所在的目錄為當前父目錄的人為手動建立的com\cjren\util目錄下。
    import com.cjren.util.ClassA;
    public class ClassB {
    ? ... // use ClassA here
    }

    To compile: javac ClassB.java
    錯誤信息是
    "ClassB.java:某一行: 無法訪問 com.cjren.swing.ClassA
    ?錯誤的類文件: .\com\cjren\util\ClassA.class
    ?類文件包含錯誤的類: ClassA
    ?請刪除該文件或確保該文件位于正確的類路徑子目錄中。"
    想一想為什么出錯信息是說:“錯誤的類文件: .\com\cjren\util\ClassA.class,類文件包含錯誤的類: ClassA”呢?因為你這個com.cjren.util包中的ClassA.class文件本來所默認的包信息是".",在ClassA.java中并沒有使用"package"語句指定ClassA應該屬于包com\cjren\util這個信息。

    小結:
    在嘗試過程當中發(fā)現(xiàn),
    public class ClassA {
    ? ...
    }

    package com.cjren.util;
    public class ClassA {
    ? ...
    }
    這兩個只差了一個package語句的class文件大小有十幾到幾十k上的區(qū)別,這可能進一步證明了.java文件中的package語句會在.class文件中加入相應的包信息,這個包信息決定了這個class被使用時候的方式(是否需要import特定的包)。
    還有一點要注意的是:
    package com.cjren.util;
    public class ClassA {
    ? ...
    }
    之后無論是使用 javac ClassA.java 或者 javac -d . ClassA.java編譯都不會影響ClassA.class文件當中所含有的包信息,這兩種編譯方式所造成的區(qū)別在上面的使用說明中已經(jīng)說過了。


    ?

    posted @ 2006-07-06 09:00 cjren 閱讀(823) | 評論 (3)編輯 收藏
     

    2006-6-24

    嘗試以一個例子來說明搭建一個 project 時候的目錄構建情況。

    ?

    情況一

    下面以一個地圖編輯器的例子為例

    project mapeditor

    父目錄是
    ”project mapeditor”,

    .\Image 程序使用到的圖片。

    .\Maps 程序運行時用戶保存的自定義地圖。

    .\com 主程序 MapEditor.java 將會是用到的 package 的源文件。

    .\com\cjren\swing\MyFilter.java

    MapEditor.java 主程序源文件,代碼中沒有 ”package” 語句。

    runMapEditor.bat 完成編譯和運行所需的所有工作。

    ?

    下面主要看看 runMapEditor.bat 的內容:

    @echo off

    rem output the date and time

    date /T

    time /T

    echo welcome to my map editor :-)

    ?

    rem make the directory for class files

    mkdir .\build\classes

    ?

    rem compile the source files

    javac -d .\build\classes MapEditor.java

    ?

    rem run the application,

    rem but you must avoid this: java.\build\classes\MapEditor,

    rem which will be an error

    java -cp .\build\classes MapEditor

    ?

    rem clean everything in the build folder

    rmdir .\build /S /Q

    ?

    pause

    ?

    從上面的具體代碼中可以看出在編譯和運行的時候,所有的 class 文件都回被放在 .\build\classes 這個文件夾中,這個文件夾是動態(tài)生成并且最后會被清楚掉的。

    ?

    這里有三個值得注意的地方。

    一,通過 ” javac -d .\build\classes MapEditor.java” ,不單只是 MapEditor.java 所定義的 class 都被放于 .\build\classes 中,甚至連 .\com MyFilter.java 所對應的 class 也都在 .\build\classes\com\cjren\swing 中,而 com 包在 .\bulid\classes 下是自動被準確生成的。也就是說所有的 .class 文件都被放在 .\bulid\classes 文件夾中了。

    二,當使用 ”java -cp .\build\classes MapEditor” 來運行程序的時候,并沒有因為 Image 文件夾不在 .\build\classes 而出錯。這說明了 .java 文件中的代碼已經(jīng)決定了它所使用到的 Image 文件夾的位置,這個位置是相對于 .java 文件所在的位置來說的,而不是 .class

    三,我嘗試了在 d 盤下新建了一個 a 目錄,然后把

    javac -d .\build\classes MapEditor.java

    java -cp .\build\classes MapEditor

    換成

    javac -d d:\a MapEditor.java

    java -cp d:\a MapEditor

    之后,其他 ”project mapeditor” 下的所有東西都沒有改變,程序依然成功執(zhí)行。這就進一步證明了 .java 文件中的代碼決定了所有其他目錄或文件元素的相對位置,這個位置以 .java 文件所在的目錄為標準。而與 .class 文件的路徑無關。但是:別混淆了 A.class 它所使用到的包的 .class 的路徑是以 A.class 文件的路徑為標準的!!!這就與上面 MapEditor.class 也和(必須和) com 包同處于 bulid\classes 目錄下沒有矛盾。

    ?

    情況二

    目的是把上面情況一中所有的文件和文件夾都包含在 src 這個文件夾中,而 src 本身就是父目錄 project mapeditor2 下的一個文件夾。而且我希望編譯時候生成的 build 文件夾和 src 文件夾的關系是:

    \project mapeditor2\src

    \project mapeditor2\build



    src
    文件夾的內容如下:

    pj2-src
    注意批處理文件
    runMapEditor.bat src 文件夾下,而且在此情況下, runMapEditor.bat 的內容將有所變化:

    @echo off

    rem output the date and time

    date /T

    time /T

    echo welcome to my map editor :-)

    ?

    rem make the directory for class files

    mkdir ..\build\classes

    ?

    rem compile the source files

    javac -d ..\build\classes MapEditor.java

    ?

    rem run the application,

    rem but you must avoid this: java.\build\classes\MapEditor,

    rem which will be an error

    java -cp ..\build\classes MapEditor

    ?

    rem clean everything in the build folder

    rmdir ..\build /S /Q

    ?

    pause

    ?

    情況一和情況二的差別不大,只是源代碼文件多一層的文件夾的包裹。而且最大的共同點是 runMapEditor.bat 和源代碼文件在同一個文件夾下。

    ?

    情況三

    嘗試在情況二的基礎上把 runMapEditor.bat 提到和 src 以及 build 相同的父目錄下。假設父目錄是 project mapeditor3 ,則:

    pj3
    現(xiàn)在
    runMapEditor.bat 的內容是:

    @echo off

    rem output the date and time

    date /T

    time /T

    echo welcome to my map editor :-)

    ?

    rem make the directory for class files

    mkdir .\build\classes

    ?

    rem go into the src directory

    cd src

    ?

    rem compile the source files

    javac -d ..\build\classes MapEditor.java

    ?

    rem run the application,

    rem but you must avoid this: java.\build\classes\MapEditor,

    rem which will be an error

    java -cp ..\build\classes MapEditor

    ?

    rem clean everything in the build folder

    rmdir ..\build /S /Q

    ?

    pause

    ?

    在嘗試工程當中,發(fā)現(xiàn)以下的做法將找不到 Image 文件夾:

    cd src

    javac -d ..\build\classes MapEditor.java

    cd ..

    java -cp .\build\classes MapEditor

    這種修改所造成的區(qū)別是運行 ”java” 命令的位置不同了。可以猜想是需要在 src 文件夾內運行 java 命令,而 src 文件夾中含有所有程序所需的代碼和 image 素材。

    ?

    下面提供一個稍微不同的批處理文件, runMapEditor2.bat ,它也同樣處于 project mapeditor3 這個父目錄下:

    pj3-

    runMapEditor2.bat
    的內容如下:

    @echo off

    mkdir d:\a

    cd src

    javac -d d:\a MapEditor.java

    java -cp d:\a MapEditor

    rmdir d:\a /S /Q

    pause

    這個修改過的例子把 class 文件都移到較遠的地方 (d:\a) ,但是還可以成功運行。小結一下它能成功運行的特點:

    一, src 文件夾中已經(jīng)包含了所有的元素,包括所需的外部 package 代碼,包括 image 文件夾。這些元素都必須使得主程序 .java 能成功的編譯。

    二,運行 ”java” 命令都在 src 這個目錄下。也就是說都在和代碼處在相同的文件路徑下,而不是其他任何路徑。

    ?

    情況一都三的小結

    基本滿足了在 windows 系統(tǒng)下開發(fā)小項目的需求,我在這三個嘗試的例子中主程序 MapEditor.java 都沒有含有 ”package main” 這類的打包語句。

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

    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的時候,需要兩個環(huán)境變量。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文件統(tǒng)一都放在同一個目錄之下,倒也相安無事而且省事。但是在做畢設(坦克對戰(zhàn)游戲)的時候,多則二十個的源文件,再連同那些class文件都放在一個目錄下,顯得非常的雜亂。于是覺得是時候考慮一下一個project的目錄結構了,例如把源文件和class文件分開,把測試文件也統(tǒng)一在另一個獨立的目錄下。

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

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

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

    (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)編輯 收藏
     
    主站蜘蛛池模板: 亚洲免费观看在线视频| 18女人腿打开无遮掩免费| 亚洲国产精品日韩在线| 亚洲精品国产电影| 青青青青青青久久久免费观看| 男人的天堂亚洲一区二区三区| 香蕉视频在线免费看| 亚洲无人区码一二三码区别图片| 亚洲av伊人久久综合密臀性色| 亚洲国产精品一区二区第四页| 中文字幕无码不卡免费视频| 久久久久国产免费| 精品国产免费人成网站| 美女羞羞视频免费网站| 亚洲乱码av中文一区二区| 亚洲国产美女视频| 亚洲邪恶天堂影院在线观看| 亚洲中文字幕无码永久在线| 国产精品久久香蕉免费播放| 啦啦啦中文在线观看电视剧免费版 | mm1313亚洲精品无码又大又粗 | 亚洲国产综合精品| 亚洲AV无码乱码在线观看裸奔| 91麻豆精品国产自产在线观看亚洲| 午夜国产羞羞视频免费网站| 在线成人a毛片免费播放 | 亚洲一卡二卡三卡| 亚洲精品美女久久久久| 亚洲精品在线视频观看| 久久亚洲AV无码精品色午夜| 亚洲人成电影福利在线播放 | WWW国产亚洲精品久久麻豆| 亚洲自国产拍揄拍| 亚洲一区二区三区91| 91亚洲精品自在在线观看| 亚洲网站视频在线观看| 亚洲综合在线成人一区| 亚洲精品福利网泷泽萝拉| 亚洲视频在线免费看| 亚洲无线一二三四区| 亚洲av日韩av综合|