以前的项目都是用别人的build.xml
下定决心自己写一个build.xml
以加深对软件的理解:
下下第一版。
根目录下写了一个build.xml
当然这是用myecllips生成的项目了。
<?xml version ="1.0" ?>
<project name="neutral" default="all" basedir="." >
<!-- =================================
target: all
================================= -->
<target name="all" description="--> description">
</target>
</project>
ctrl+alt+x+q运行一下
引用
Buildfile: C:\Documents and Settings\maomao\workspace\neutral\build.xml
all:
BUILD SUCCESSFUL
Total time: 125 milliseconds
看来没问题。
------------------------------------
下一步
构建目录树:
1.src/java是放源码的
2.src/test是放测试与mock代码的。
3.src/source放配置文件用。
-------------------
以上三个目录在eclipse中指向neutral/WebRoot/WEB-INF/classes
-------------------
4.testlib是放测试时才会用到的包
5.userlib放运行时用的包。
添加目录定义区
<?xml version ="1.0" ?>
<project name="neutral" default="all" basedir="." >
<!-- =================================
target: all
================================= -->
<target name="all" description="--> description">
<echo message="mynameis">maodajun</echo>
</target>
<property name="build.dir" location="build" description=""/><!-- ANT 临时 文件 区-->
<property name="src.dir" location="src" description=""/><!--源文件区 -->
<property name="product.class" location="${build.dir}/product" description="成品区"/><!--成品存放区 -->
<property name="source.class" location="${build.dir}/class" description="编译区" /><!-- 源文件编译区-->
<property name="junittest.class" location="${build.dir}/test" description="测试编译区"/><!—单元测试文件编译区-->
<property name="source.dir" location="${src.dir}/java" description=" 源码"/><!-- 源代码-->
<property name="junittest.dir" location="${src.dir}/test" description=" 测试码"/><!-- 测试码-->
<property name="context.dir" location="${src.dir}/source" description="配置区"/><!-- 应用配置文件-->
<property name="jsp.dir" location="WebRoot/WebRoot/WEB-INF/jsp" description="配置区"/><!-- 应用配置文件-->
<property name="user.lib" location="lib/user" description="用户库"/><!-- 用户所需要的lib 库-->
<property name="test.lib" location="lib/test" description="测试库"/> <!-- 测试所需要的lib 库 -->
<echo>
+--${product.class}
|--${source.class}
|--${test.class}
+--${source.dir}
|--${junittest.dir}
|--${context.dir}
|--${jsp.dir}
+--${user.lib}
|--${test.lib}
</echo>
</project>
引用
Buildfile: C:\Documents and Settings\maomao\workspace\neutral\build.xml
[echo] +--C:\Documents and Settings\maomao\workspace\neutral\build\product
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\build\class
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\build\test
[echo] +--C:\Documents and Settings\maomao\workspace\neutral\src\java
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\src\test
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\src\source
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\WebRoot\WebRoot\WEB-INF\jsp
[echo] +--C:\Documents and Settings\maomao\workspace\neutral\lib\user
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\lib\test
all:
[echo] mynameismaodajun
BUILD SUCCESSFUL
Total time: 187 milliseconds
―――――――――――――――――――――――――
重头戏。。。。
编译过程叫compile
----
注1:在all中加入compile
否则是不会运行地。。。。。。。
注2:在源目录下写个程序吧。。。。。
package com.alcargo.tianhangteam.tools;
import org.apache.log4j.Logger;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("hellowrld");
}
}
<?xml version ="1.0" ?>
<project name="neutral" default="all" basedir="." >
<!-- =================================
target: all
================================= -->
<target name="all" depends="compile" description="--> description">
<echo message="mynameis">maodajun</echo>
</target>
<property name="build.dir" location="build" description=""/><!-- ANT 临时 文件 区-->
<property name="src.dir" location="src" description=""/><!--源文件区 -->
<property name="product.class" location="${build.dir}/product" description="成品区"/><!--成品存放区 -->
<property name="source.class" location="${build.dir}/class" description="编译区" /><!-- 源文件编译区-->
<property name="junittest.class" location="${build.dir}/test" description="测试编译区"/><!-- 测试文件编译区-->
<property name="source.dir" location="${src.dir}/java" description=" 源码"/><!-- 源代码-->
<property name="junittest.dir" location="${src.dir}/test" description=" 测试码"/><!-- 测试码-->
<property name="context.dir" location="${src.dir}/source" description="配置区"/><!-- 应用配置文件-->
<property name="jsp.dir" location="WebRoot/WebRoot/WEB-INF/jsp" description="配置区"/><!-- 应用配置文件-->
<property name="user.lib" location="lib/user" description="用户库"/><!-- 用户所需要的lib 库-->
<property name="test.lib" location="lib/test" description="测试库"/> <!-- 测试所需要的lib 库 -->
<echo>
+--${product.class}
|--${source.class}
|--${junittest.class}
+--${source.dir}
|--${junittest.dir}
|--${context.dir}
|--${jsp.dir}
+--${user.lib}
|--${test.lib}
</echo>
<!-- =================================
target: compile
================================= -->
<target name="compile" depends="" description="--> 编译源文件">
<javac srcdir="${source.dir}" destdir="${source.class}">
</javac>
</target>
</project>
引用
Buildfile: C:\Documents and Settings\maomao\workspace\neutral\build.xml
[echo] +--C:\Documents and Settings\maomao\workspace\neutral\build\product
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\build\class
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\build\test
[echo] +--C:\Documents and Settings\maomao\workspace\neutral\src\java
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\src\test
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\src\source
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\WebRoot\WebRoot\WEB-INF\jsp
[echo] +--C:\Documents and Settings\maomao\workspace\neutral\lib\user
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\lib\test
compile:
[echo] 编译
BUILD FAILED
C:\Documents and Settings\maomao\workspace\neutral\build.xml:40: destination directory "C:\Documents and Settings\maomao\workspace\neutral\build\class" does not exist or is not a directory
Total time: 234 milliseconds
没找到目录错误。。。
所以我们加入另一个任务
构造目录
<!-- - - - - - - - - - - - - - - - - -
target: 构建目录
- - - - - - - - - - - - - - - - - -->
<target name="buildingpath" description="构建所需要目录">
<echo message="构建目录"></echo>
<mkdir dir="${source.class}"/>
<mkdir dir="${junittest.class}"/>
<mkdir dir="${product.class}"/>
</target>
引用
Buildfile: C:\Documents and Settings\maomao\workspace\neutral\build.xml
[echo] +--C:\Documents and Settings\maomao\workspace\neutral\build\product
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\build\class
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\build\test
[echo] +--C:\Documents and Settings\maomao\workspace\neutral\src\java
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\src\test
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\src\source
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\WebRoot\WebRoot\WEB-INF\jsp
[echo] +--C:\Documents and Settings\maomao\workspace\neutral\lib\user
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\lib\test
buildingpath:
[echo] 构建目录
[mkdir] Created dir: C:\Documents and Settings\maomao\workspace\neutral\build\class
[mkdir] Created dir: C:\Documents and Settings\maomao\workspace\neutral\build\test
[mkdir] Created dir: C:\Documents and Settings\maomao\workspace\neutral\build\product
compile:
[echo] 编译
[javac] Compiling 2 source files to C:\Documents and Settings\maomao\workspace\neutral\build\class
all:
[echo] mynameismaodajun
BUILD SUCCESSFUL
Total time: 1 second
顺序没关系只要依赖对了就OK
不过第二次的日志就成这样子了
引用
Buildfile: C:\Documents and Settings\maomao\workspace\neutral\build.xml
[echo] +--C:\Documents and Settings\maomao\workspace\neutral\build\product
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\build\class
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\build\test
[echo] +--C:\Documents and Settings\maomao\workspace\neutral\src\java
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\src\test
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\src\source
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\WebRoot\WebRoot\WEB-INF\jsp
[echo] +--C:\Documents and Settings\maomao\workspace\neutral\lib\user
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\lib\test
buildingpath:
[echo] 构建目录
compile:
[echo] 编译
all:
[echo] mynameismaodajun
BUILD SUCCESSFUL
Total time: 718 milliseconds
<?xml version ="1.0" ?>
<project name="neutral" default="all" basedir="." >
<!-- =================================
target: all
================================= -->
<target name="all" depends="clean,compile" description="--> description">
<echo message="mynameis">maodajun</echo>
</target>
<property name="build.dir" location="build" description=""/><!-- ANT 临时 文件 区-->
<property name="src.dir" location="src" description=""/><!--源文件区 -->
<property name="product.class" location="${build.dir}/product" description="成品区"/><!--成品存放区 -->
<property name="source.class" location="${build.dir}/class" description="编译区" /><!-- 源文件编译区-->
<property name="junittest.class" location="${build.dir}/test" description="测试编译区"/><!-- 测试文件编译区-->
<property name="source.dir" location="${src.dir}/java" description=" 源码"/><!-- 源代码-->
<property name="junittest.dir" location="${src.dir}/test" description=" 测试码"/><!-- 测试码-->
<property name="context.dir" location="${src.dir}/source" description="配置区"/><!-- 应用配置文件-->
<property name="jsp.dir" location="WebRoot/WebRoot/WEB-INF/jsp" description="配置区"/><!-- 应用配置文件-->
<property name="user.lib" location="lib/user" description="用户库"/><!-- 用户所需要的lib 库-->
<property name="test.lib" location="lib/test" description="测试库"/> <!-- 测试所需要的lib 库 -->
<echo>
+--${product.class}
|--${source.class}
|--${junittest.class}
+--${source.dir}
|--${junittest.dir}
|--${context.dir}
|--${jsp.dir}
+--${user.lib}
|--${test.lib}
</echo>
<!-- =================================
target: compile
================================= -->
<target name="compile" depends="buildingpath" description="--> 编译源文件">
<echo message="编译"></echo>
<javac srcdir="${source.dir}" destdir="${source.class}">
</javac>
</target>
<!-- - - - - - - - - - - - - - - - - -
target: 构建目录
- - - - - - - - - - - - - - - - - -->
<target name="buildingpath" description="构建所需要目录">
<echo message="构建目录"></echo>
<mkdir dir="${source.class}"/>
<mkdir dir="${junittest.class}"/>
<mkdir dir="${product.class}"/>
</target>
<!-- - - - - - - - - - - - - - - - - -
target: 清除上次的文件
- - - - - - - - - - - - - - - - - -->
<target name="clean" description="删除编译文件与文件所在的目录">
<echo message="清除临时文件目录"></echo>
<deltree dir="${build.dir}"/>
</target>
</project>
引用
Buildfile: C:\Documents and Settings\maomao\workspace\neutral\build.xml
[echo] +--C:\Documents and Settings\maomao\workspace\neutral\build\product
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\build\class
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\build\test
[echo] +--C:\Documents and Settings\maomao\workspace\neutral\src\java
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\src\test
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\src\source
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\WebRoot\WebRoot\WEB-INF\jsp
[echo] +--C:\Documents and Settings\maomao\workspace\neutral\lib\user
[echo] |--C:\Documents and Settings\maomao\workspace\neutral\lib\test
clean:
[echo] 清除临时文件目录
[deltree] DEPRECATED - The deltree task is deprecated. Use delete instead.
[deltree] Deleting: C:\Documents and Settings\maomao\workspace\neutral\build
buildingpath:
[echo] 构建目录
[mkdir] Created dir: C:\Documents and Settings\maomao\workspace\neutral\build\class
[mkdir] Created dir: C:\Documents and Settings\maomao\workspace\neutral\build\test
[mkdir] Created dir: C:\Documents and Settings\maomao\workspace\neutral\build\product
compile:
[echo] 编译
[javac] Compiling 2 source files to C:\Documents and Settings\maomao\workspace\neutral\build\class
all:
[echo] mynameismaodajun
BUILD SUCCESSFUL
Total time: 1 second