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

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

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

    我要啦免费统计

    微藍領域

    我的學習檔案館
    posts - 19, comments - 57, trackbacks - 0, articles - 57
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    ANT使用

    Posted on 2007-10-23 12:14 hilor 閱讀(1169) 評論(0)  編輯  收藏 所屬分類: J2EE

      ant是jakarta一個非常好的OpenSource子項目,是基于java的編譯工具。下面簡單介紹一下在linux環境中如何安裝ant:

      1.下載
      從 http://ant.apache.org/bindownload.cgi
    可以下載最新的tar包:apache-ant-1.6.2.tar.gz,如果是windows環境則是zip文件,解壓后,在系統環境變量里設置
    ANT_HOME為f:\project\tools\apache-ant-1.6.2,并將f:\project\tools\apache-ant
    -1.6.2\bin目錄添加到classpath中,然后就可以使用了

      2.安裝,解壓到/usr/local下
    > tar zxpvf apache-ant-1.6.2.tar.gz
    > ln -s apache-ant-1.6.2 ant

      3.設置環境
      將ANT_HOME設置到當前用戶的.bash_profile文件/home/admin/.bash_profile

    [admin@tangtang home]$ su - admin
    [admin@tangtang home]$ vi .bash_profile
    export ANT_HOME=/usr/local/ant
    export PATH=/usr/local/ant/bin:$PATH

      如果是windows環境,需要設置%ANT_HOME%,并把%ANT_HOME%\bin目錄全路徑加入到%path%中

      4.測試
      用ant命令測試運行情況
    [admin@tangtang home]$ ant
    Buildfile: build.xml does not exist!
    Build failed

    [admin@tangtang home]$ ant -version
    Apache Ant version 1.6.2 compiled on July 16 2004

      若出現這樣的錯誤:Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/launch/Launcher
      這是linux系統默認安裝了一些ant的lib,修改 /etc/ant.conf中 ANT_HOME=/usr/share/ant 為你正確安裝ant的地址,如 /usr/local/ant

      5、build腳本
      如果是在linux環境中,下面是build腳本的一個范例:

    #build腳本
    #! /bin/sh
    # 進入到上級目錄
    cd `dirname $0`/..
    # 獲取當前目錄為PROJECT_HOME
    PROJECT_HOME=`pwd`
    # 設置JAVA_HOME
    export JAVA_HOME=/usr/cyber/java
    # 得到CLASSPATH
    CLASSPATH1=$CLASSPATH
    # 添加CLASSPATH
    CLASSPATH=${PROJECT_HOME}\webapps\WEB-INF\conf:${PROJECT_HOME}\webapps\WEB-INF\classes:$CLASSPATH
    # ant build,-buildfile 參數,是使用自定義的build.xml文件,$@是參數數組
    /usr/local/ant/bin/ant -buildfile ${PROJECT_HOME}/build/build.xml "$@"
    # build腳本結束

      如果是在windows環境中,下面是build.bat腳本的一個范例:

    # build.bat 
    # 關閉echo顯示
    @echo off
    # 設置%JAVA_HOME%
    if "%JAVA_HOME%"=="" set JAVA_HOME=f:\tools\java
    # 設置%ANT_HOME%
    if "%ANT_HOME%"=="" set ANT_HOME=f:\tools\ant
    # 設置PROJECT_HOME
    set PROJECT_HOME = %CD%\..
    set CLASSPATH_BAK=%CLASSPATH%
    set CLASSPATH=
    # 執行build
    %ANT_HOME%\bin\ant.bat -buildfile ..\build\build.xml %1 %2 %3 %4 %5 %6 %7 %8 %9

      6、build配置文件
      在${PROJECT_HOME}/build目錄下面,需要定義兩個文件,一個是build.properties,一個是build.xml
      build.properties文件定義了build的一些常量

    # build.properties
    project = tangtang
    version = 1.1.1
    # 采用classic編譯,即采用ant編譯
    build.compiler = classic
    # 采用jikes編譯
    #build.compiler = jikes

    year = 2004
    debug = on
    optimize = on
    deprecation = on

    os = linux
    author = tangtang
    email = syvin_tom@hotmail.com
    url = www.tangtang.org
    company = tangtang.org

    build.xml文件是ant編譯的主要配置文件,ant功能強大,需要通過相應的配置項來表現。
    <?xml version="1.0" encoding="gb2312"?>

    <!-- Build file for project -->

    <project name="cyber" default="jar" basedir=".">
    <property file="${user.home}/.ant.properties" />
    <!-- ant build properties -->
    <property file="build.properties"/>

    <property name="build.dir" value=".."/>
    <property name="build.src" value="${build.dir}/webapps/WEB-INF/src/java"/>
    <property name="build.dest" value="${build.dir}/webapps/WEB-INF/classes"/>
    <property name="build.lib" value="${build.dir}/webapps/WEB-INF/lib"/>
    <property name="build.ext" value="./lib"/>
    <property name="build.tpl" value="${build.dir}/webapps/WEB-INF/templates"/>
    <property name="build.encoding" value="gb2312"/>

    <property name="src.java.dir" value="../src/java"/>
    <property name="javadoc.destdir" value="../docs/api"/>
    <property name="javadoc.link" value="http://www.tangtang.org/java/docs/api/"/>
    <property name="final.name" value="${project}-${version}"/>
    <property name="dist.root" value="${build.dir}/dist"/>
    <property name="dist.dir" value="${dist.root}/${final.name}"/>

    <path id="classpath">
    <pathelement path="${java.class.path}/"/>
    <fileset dir="${build.lib}">
    <include name="*.jar"/>
    </fileset>
    <fileset dir="${build.ext}">
    <include name="*.jar"/>
    </fileset>
    </path>

    <property name="classpath" refid="classpath"/>
    <!-- =================================================================== -->
    <!-- prints the environment -->
    <!-- =================================================================== -->
    <target name="env">
    <echo message="build.compiler = ${build.compiler}"/>
    <echo message="java.home = ${java.home}"/>
    <echo message="user.home = ${user.home}"/>
    <!--echo message="java.class.path = ${java.class.path}"/-->
    <echo message="classpath = ${classpath}"/>
    </target>

    <!-- =================================================================== -->
    <!-- Prepares the build directory -->
    <!-- =================================================================== -->
    <target name="prepare" depends="env">

    <tstamp/>
    <filter token="year" value="${year}"/>
    <filter token="version" value="${version}"/>
    <filter token="date" value="${DSTAMP}"/>
    <!--
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${build.dest}"/>
    <mkdir dir="${build.src}"/>
    -->
    <!-- chose a class that's from j2ee.jar -->
    <available classname="javax.sql.DataSource"
    property="J2EE.present">
    <classpath refid = "classpath"/>
    </available>
    </target>
    <target name="J2EE-error" depends="prepare" unless="J2EE.present">

    <echo>
    ********************************************************
    **
    ** J2EE has not been found and is needed for the target
    ** you have chosen
    **
    ** Since CLASSPATH is an evil idea, just link or drop
    ** a copy of your j2ee.jar into build/lib directory.
    **
    *********************************************************
    </echo>
    </target>

    <target name="init">
    <echo>
    build init
    build compile
    </echo>
    <mkdir dir="${build.dir}/data"/>
    <mkdir dir="${build.dir}/logs"/>
    <mkdir dir="${build.dir}/dist"/>
    </target>

    <target name="jar" depends="compile">
    <mkdir dir="${dist.root}"/>
    <delete dir="${dist.root}/${project}-${version}.jar"/>
    <jar jarfile="${dist.root}/${project}-${version}.jar">
    <fileset dir="${build.dest}">
    <include name="org/tangtang/**"/>
    <exclude name="org/tangtang/test/**"/>
    </fileset>
    </jar>
    </target>

    <target name="srcjar" depends="prepare">
    <delete dir="${dist.root}/${project}-${version}-src.jar"/>
    <jar jarfile="${dist.root}/${project}-${version}-src.jar">
    <fileset dir="${build.src}">
    <include name="org/tangtang/**"/>
    <include name="org/tangtang/test/**"/>
    </fileset>
    </jar>
    </target>

    <target name="tpl" depends="env">
    <jar jarfile="${dist.root}/${project}-${version}-tpl.jar">
    <fileset dir="${build.tpl}">
    <include name="tangtang/**"/>
    </fileset>
    </jar>
    </target>

    <target name="javadocs">
    <mkdir dir="${build.dir}/docs/api"/>
    <javadoc
    sourcepath="${build.src}"
    overview="${build.dir}/docs/overview.html"
    packagenames="org.tangtang.*"
    destdir="${build.dir}/docs/api"
    encoding="${build.encoding}"
    author="true"
    version="true"
    use="true"
    link="${javadoc.link}"
    windowtitle="${project} ${version} API"
    doctitle="${project} ${version} API"
    bottom="Copyright &copy; ${year} tangtang.org. All Rights Reserved."
    >
    <tag name="todo" description="To Do:"/>
    </javadoc>
    </target>

    <target name="poolman" depends="prepare">
    <jar jarfile="${dist.root}/poolman.jar">
    <fileset dir="${build.dest}">
    <include name="com/codestudio/**"/>
    </fileset>
    </jar>
    </target>

    <target name="nightly" depends="prepare">
    <tstamp/>
    <jar jarfile="${dist.root}/nightly/${project}-${version}-${DSTAMP}-src.jar">
    <fileset dir="${build.src}">
    <include name="org/tangtang/**"/>
    </fileset>
    </jar>
    </target>

    <target name="compile" depends="prepare">
    <mkdir dir="${build.dest}"/>

    <!-- 檢查依賴性 -->
    <depend srcdir="${build.src}"
    destdir="${build.dest}"
    cache="${build.dest}">
    <classpath refid="classpath"/>
    </depend>

    <javac srcdir="${build.src}"
    destdir="${build.dest}"
    debug="${debug}"
    deprecation="${deprecation}"
    optimize="${optimize}">
    <classpath refid="classpath"/>
    </javac>
    </target>

    <target name="clean">
    <delete>
    <fileset dir="${build.dest}">
    <include name="**/*.class"/>
    </fileset>
    </delete>
    </target>

    <target name="clean_dist">
    <delete>
    <fileset dir="${dist.root}" includes="*"/>
    </delete>
    <delete dir="${dist.dir}" quiet="false"/>
    </target>

    <target name="deploy" depends="jar">
    <mkdir dir="${dist.dir}/data"/>
    <mkdir dir="${dist.dir}/logs"/>

    <copy todir="${dist.dir}/bin">
    <fileset dir="${build.dir}/bin">
    <include name="*"/>
    </fileset>
    </copy>

    <fixcrlf srcdir="${dist.dir}/bin" eol="lf" eof="remove"
    includes="**/*"
    excludes="**/*.bat"
    />

    <copy todir="${dist.dir}/conf">
    <fileset dir="${build.dir}/conf">
    <include name="templates/*"/>
    <exclude name="*"/>
    <exclude name="**/*.bak"/>
    <exclude name="**/bak/**"/>
    </fileset>
    </copy>

    <copy todir="${dist.dir}/build">
    <fileset dir="${build.dir}/build">
    <include name="*"/>
    <include name="lib/*"/>
    <exclude name="**/*.bak"/>
    <exclude name="**/bak/**"/>
    </fileset>
    </copy>

    <copy todir="${dist.dir}/templates">
    <fileset dir="${build.dir}/templates">
    <include name="**/*.vm"/>
    <exclude name="**/*.bak"/>
    <exclude name="**/bak/**"/>
    </fileset>
    </copy>

    <copy todir="${dist.dir}/webapps/html">
    <fileset dir="${build.dir}/webapps/html">
    <include name="**/*"/>
    <exclude name="**/*.bak"/>
    <exclude name="**/bak/**"/>
    </fileset>
    </copy>

    <copy todir="${dist.dir}/webapps/applet">
    <fileset dir="${build.dir}/webapps/applet">
    <include name="**/*"/>
    <exclude name="**/*.bak"/>
    <exclude name="**/bak/**"/>
    </fileset>
    </copy>

    <copy todir="${dist.dir}/webapps/icons">
    <fileset dir="${build.dir}/webapps/icons">
    <include name="**/*.gif"/>
    <include name="**/*.jpg"/>
    <exclude name="**/*.bak"/>
    <exclude name="**/bak/**"/>
    </fileset>
    </copy>

    <copy todir="${dist.dir}/webapps/images">
    <fileset dir="${build.dir}/webapps/images">
    <include name="**/*.gif"/>
    <include name="**/*.jpg"/>
    <exclude name="**/*.bak"/>
    <exclude name="**/bak/**"/>
    </fileset>
    </copy>

    <copy todir="${dist.dir}/webapps/WEB-INF/">
    <fileset dir="${build.dir}/webapps/WEB-INF/">
    <include name="**/*"/>
    <exclude name="classes/**"/>
    <exclude name="conf/*"/>
    <exclude name="src/**"/>
    </fileset>
    </copy>

    <jar jarfile="${dist.root}/${project}-${version}-war.jar">
    <fileset dir="${dist.dir}">
    <include name="**/*"/>
    </fileset>
    </jar>
    </target>

    <target name="conf">
    <delete>
    <fileset dir="${build.dir}/conf" includes="*"/>
    <fileset dir="${build.dir}/webapps/WEB-INF/conf" includes="*"/>
    </delete>
    <filter filtersfile="deploy.properties"/>
    <copy todir="${build.dir}/conf" filtering="true">
    <fileset dir="${build.dir}/conf/templates">
    <include name="*"/>
    </fileset>
    </copy>
    <copy todir="${build.dir}/webapps/WEB-INF/conf" filtering="true">
    <fileset dir="${build.dir}/webapps/WEB-INF/conf/templates">
    <include name="*"/>
    </fileset>
    </copy>
    </target>
    </project>
    主站蜘蛛池模板: 免费国产真实迷j在线观看| 大学生一级毛片免费看| 免费一级毛片清高播放| 亚洲AV成人一区二区三区观看| 99精品全国免费观看视频| 亚洲看片无码在线视频 | 大学生高清一级毛片免费| 亚洲一区二区三区高清视频| 国产在线观看免费观看不卡| 亚洲人成免费网站| 免费看大美女大黄大色| 亚洲AV网一区二区三区| 国产日产亚洲系列最新| 在线观看片免费人成视频无码| 亚洲av无码一区二区三区乱子伦| a级毛片毛片免费观看久潮| 亚洲第一福利视频| 18禁免费无码无遮挡不卡网站 | 亚洲精品网站在线观看你懂的| 亚洲免费观看在线视频| 国产AV旡码专区亚洲AV苍井空| 国产成人免费a在线视频色戒| 一级毛片视频免费| 亚洲AV无码一区二区二三区软件| 18观看免费永久视频| 亚洲熟女www一区二区三区| 夜色阁亚洲一区二区三区| 国产麻豆一精品一AV一免费 | 亚洲精品天堂无码中文字幕| 亚洲电影日韩精品 | 免费a级黄色毛片| 国产无遮挡色视频免费观看性色| 亚洲AV福利天堂一区二区三| 无码精品A∨在线观看免费| 色天使色婷婷在线影院亚洲| 久久精品国产精品亚洲精品| 亚洲色图在线观看| 日韩免费高清一级毛片在线| 中文字幕一区二区三区免费视频| 亚洲精品美女在线观看| 亚洲欧洲精品成人久久曰影片|