JAVA進行式
          讓我們把JAVA進行到底!
          posts - 13,comments - 21,trackbacks - 0

          說明:
          ??????? 下面是我在開發中使用的build.xml文件以及其附屬文件,為使層次清晰我將公用任務放入common.xml中,另外還有一些配置文件,這個build.xml會在今后開發中不斷完善。

          ??????? 1、build.xml文件
          <?xml version="1.0" encoding="gb2312"?>
          <project name="message" basedir="." default="help">
          ? <property name="webapp.name" value="message"/>
          ? <import file="../message/common.xml"/>

          ? <!-- "test" 任務用于執行junit的單元測試 -->
          ? <target name="test" description="Run junit test.">
          ??? <mkdir dir="${build.dir}/test"/>
          ??? <mkdir dir="${build.dir}/report"/>
          ??
          ??? <junit printsummary="yes">
          ????? <formatter type="xml"/>
          ?? <test name="cn.hxex.message.test.AllTests"/>
          ?? <classpath refid="classpath"/>
          ??? </junit>
          ???
          ??? <junitreport todir="${build.dir}/test">
          ????? <fileset dir=".">
          ???? <include name="TEST-*.xml"/>
          ?? </fileset>
          ?? <report format="noframes" todir="${build.dir}/report"/>
          ??? </junitreport>
          ? </target>
          ?
          ? <!-- "run"任務用于運行指定程序 -->?
          ? <target name="run">
          ??? <java classname="cn.hxex.basic.exercise.LifeCycle">
          ????? <classpath refid="classpath"/>
          ??? </java>
          ? </target>
          </project>

          ??????? 2、common.xml文件
          <?xml version="1.0" encoding="gb2312"?>
          <project>
          ? <!-- 直接設置項目文件夾變量,也可以寫一個配置文件,用file屬性引入 -->
          ? <!--
          ? <property file="webapp.properties"/>
          ?? -->
          ? <property name="src.dir" value="src"/>
          ? <property name="build.dir" value="WebRoot"/>
          ? <property name="webpage.dir" value="${build.dir}/webpage"/>
          ? <property name="webinf.dir" value="${build.dir}/webinf"/>
          ? <property name="lib.dir" value="${webinf.dir}/lib"/>
          ? <property name="classes.dir" value="${webinf.dir}/classes"/>
          ?
          ? <!-- 取得環境變量TOMCAT_HOME的值 -->
          ? <property environment="env"/>
          ? <property name="tomcat.home" value="${env.TOMCAT_HOME}"/>
          ? <property name="ant.home" value="${env.ANT_HOME}"/>
          ?
          ? <!-- 引入有關tomcat的變量配置文件,也可以象上面一樣,直接在這里設置 -->
          ? <property file="tomcat.properties"/>
          ? <!--
          ? <property name="tomcat.server" value="localhost"/>
          ? <property name="tomcat.manager.url" value="http://${tomcat.server}/manager"/>
          ? <property name="tomcat.username" value="admin"/>
          ? <property name="tomcat.password" value=""/>
          ?? -->
          ?
          ? <!-- 設置任務要執行的類操作 -->
          ? <!-- 可引入設置tomcat任務的配置文件 -->
          ? <taskdef file="tomcatTasks.properties">
          ??? <classpath>
          ????? <pathelement path="${tomcat.home}/server/lib/catalina-ant.jar"/>
          ??? </classpath>
          ? </taskdef>
          ?
          ? <!-- 也可逐一設置任務
          ? <taskdef name="deployc" classname="org.apache.catalina.ant.DeployTask">
          ??? <classpath>
          ????? <pathelement path="${tomcat.home}/server/lib/catalina-ant.jar"/>
          ??? </classpath>
          ? </taskdef>
          ?
          ? <taskdef name="install" classname="org.apache.catalina.ant.InstallTask">
          ??? <classpath>
          ????? <pathelement path="${tomcat.home}/server/lib/catalina-ant.jar"/>
          ??? </classpath>
          ? </taskdef>
          ?
          ? <taskdef name="list" classname="org.apache.catalina.ant.ListTask">
          ??? <classpath>
          ????? <pathelement path="${tomcat.home}/server/lib/catalina-ant.jar"/>
          ??? </classpath>
          ? </taskdef>
          ?
          ? <taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
          ??? <classpath>
          ????? <pathelement path="${tomcat.home}/server/lib/catalina-ant.jar"/>
          ??? </classpath>
          ? </taskdef>
          ?
          ? <taskdef name="remove" classname="org.apache.catalina.ant.RemoveTask">
          ??? <classpath>
          ????? <pathelement path="${tomcat.home}/server/lib/catalina-ant.jar"/>
          ??? </classpath>
          ? </taskdef>
          ?
          ? <taskdef name="resources" classname="org.apache.catalina.ant.ResourcesTask">
          ??? <classpath>
          ????? <pathelement path="${tomcat.home}/server/lib/catalina-ant.jar"/>
          ??? </classpath>
          ? </taskdef>
          ?
          ? <taskdef name="roles" classname="org.apache.catalina.ant.RolesTask">
          ??? <classpath>
          ????? <pathelement path="${tomcat.home}/server/lib/catalina-ant.jar"/>
          ??? </classpath>
          ? </taskdef>
          ?
          ? <taskdef name="start" classname="org.apache.catalina.ant.StartTask">
          ??? <classpath>
          ????? <pathelement path="${tomcat.home}/server/lib/catalina-ant.jar"/>
          ??? </classpath>
          ? </taskdef>
          ?
          ? <taskdef name="stop" classname="org.apache.catalina.ant.StopTask">
          ??? <classpath>
          ????? <pathelement path="${tomcat.home}/server/lib/catalina-ant.jar"/>
          ??? </classpath>
          ? </taskdef>
          ?
          ? <taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask">
          ??? <classpath>
          ????? <pathelement path="${tomcat.home}/server/lib/catalina-ant.jar"/>
          ??? </classpath>
          ? </taskdef>
          ? -->
          ? <!--
          ? <taskdef name="junit" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask">
          ??? <classpath>
          ????? <pathelement path="${ant.home}/lib/ant-junit.jar"/>
          ??? </classpath>
          ? </taskdef>-->
          ?????
          ? <!-- 設置類路徑 -->
          ? <path id="classpath">
          ??? <fileset dir="${lib.dir}">
          ????? <include name="*.jar"/>
          ??? </fileset>
          ?
          ??? <fileset dir="${tomcat.home}/common/lib">
          ????? <include name="*.jar"/>
          ??? </fileset>
          ???
          ??? <fileset dir="${ant.home}/lib">
          ????? <include name="*.jar"/>
          ??? </fileset>
          ???
          ??? <pathelement path="${classes.dir}"/>
          ? </path>

          ? <!-- "help"任務用于顯示幫助信息 -->
          ? <target name="help">
          ??? <echo message=""/>
          ??? <echo message="${webapp.name} build file"/>
          ??? <echo message="----------------------------------------------------------"/>
          ??? <echo message=""/>
          ??? <echo message="Available targets are:"/>
          ??? <echo message=""/>
          ??? <echo message="help??? --> Print this screen."/>
          ??? <echo message="start?? --> Start Tomcat application."/>
          ??? <echo message="stop??? --> Stop Tomcat application."/>
          ??? <echo message="list??? --> List Tomcat applications."/>
          ??? <echo message="compile --> Compile all Java files."/>
          ??? <echo message="deploy? --> Deploy the project to the tomcat."/>
          ??? <echo message="clean?? --> Clean output directories."/>
          ??? <echo message="new???? --> Creates a new project with the specified name."/>
          ??? <echo message="test??? --> Run junit test."/>
          ? </target>

          ? <!-- "start"任務用于啟動Tomcat -->
          ? <target name="start" description="Start Tomcat application">
          ??? <start url="${tomcat.manager.url}"
          ?????????? username="${tomcat.username}"
          ?????????? password="${tomcat.password}"
          ?????????? path="/${webapp.name}"/>
          ? </target>

          ? <!-- "stop"任務用于停止Tomcat -->
          ? <target name="stop" description="Stop Tomcat application">
          ??? <stop url="${tomcat.manager.url}"
          ????????? username="${tomcat.username}"
          ????????? password="${tomcat.password}"
          ????????? path="/${webapp.name}"/>
          ? </target>

          ? <!-- "list"任務用于顯示Tomcat中應用名 -->
          ? <target name="list" description="List Tomcat applications">
          ??? <list url="${tomcat.manager.url}"
          ????????? username="${tomcat.username}"
          ????????? password="${tomcat.password}"/>
          ? </target>?
          ?
          ? <!-- "clean"任務用于清除所有文件及文件夾 -->
          ? <target name="clean" description="Clean output directories">
          ??? <delete dir="${classes.dir}"/>
          ??? <delete dir="${tomcat.home}/webapps/${webapp.name}"/>
          ? </target>

          ? <!-- "compile"任務用于編譯源代碼和復制Hibernate配置文件到指定類文件夾 -->
          ? <target name="compile" description="compile the java source and copy the configuration file">
          ??? <mkdir dir="${classes.dir}"/>
          ??? <javac destdir="${classes.dir}"
          ?????????? target="1.5" source="1.5" debug="true"
          ?????????? deprecation="true" optimize="false" failonerror="true">
          ????? <src path="${src.dir}"/>
          ????? <classpath refid="classpath"/>
          ??? </javac>
          ?
          ??? <!-- 復制hibernate映射文件到項目下的classes文件中 -->
          ??? <copy todir="${classes.dir}">
          ????? <fileset dir="${src.dir}" includes="**/*.xml"/>
          ????? <fileset dir="${src.dir}" includes="**/*.properties"/>
          ??? </copy>
          ?
          ??? <!-- 復制配置文件到項目下的classes文件中 -->
          ??? <copy todir="${tomcat.home}/webapps/${webapp.name}/WEB-INF/classes">
          ????? <fileset dir="${classes.dir}" includes="**/*.xml"/>
          ????? <fileset dir="${classes.dir}" includes="**/*.properties">
          ??????? <exclude name="**/*_zh.properties"/>
          ????? </fileset>?
          ??? </copy>
          ?
          ??? <!-- 對中文配置文件進行編碼編譯 -->
          ??? <native2ascii dest="${tomcat.home}/webapps/${webapp.name}/WEB-INF/classes"
          ????????????????? encoding="UTF-8"
          ????????????????? src="${classes.dir}" includes="**/*_zh.properties"/>
          ? </target>

          ? <!-- "deploy"任務用于部署項目和復制配置文件到tomcat容器 -->
          ? <target name="deploy" depends="compile" description="deploy the project to the tomcat!">
          ??? <!-- 復制web網頁文件 -->
          ??? <copy todir="${tomcat.home}/webapps/${webapp.name}" preservelastmodified="true">
          ????? <fileset dir="${webpage.dir}">
          ??????? <include name="**/*.*"/>
          ??????? <exclude name="**/readme.txt"/>
          ????? </fileset>
          ??? </copy>
          ?
          ??? <!-- 復制類文件 -->
          ??? <copy todir="${tomcat.home}/webapps/${webapp.name}/WEB-INF/classes"
          ????????? preservelastmodified="true">
          ????? <fileset dir="${classes.dir}"/>
          ??? </copy>
          ???
          ??? <!-- 復制庫文件 -->
          ??? <copy todir="${tomcat.home}/webapps/${webapp.name}/WEB-INF/lib"
          ????????? preservelastmodified="true">
          ????? <fileset dir="${lib.dir}">
          ??????? <exclude name="**/readme.txt"/>
          ????? </fileset>
          ??? </copy>
          ?
          ??? <!-- 復制配置文件 -->
          ??? <copy todir="${tomcat.home}/webapps/${webapp.name}/WEB-INF"
          ????????? preservelastmodified="true">
          ????? <fileset dir="${webinf.dir}">
          ??????? <exclude name="**/readme.txt"/>
          ????? </fileset>
          ????? <fileset dir="${build.dir}">
          ??????? <include name="*.xml"/>
          ??????? <include name="*..properties"/>
          ????? </fileset>
          ??? </copy>
          ? </target>

          ? <!-- "new"任務用于創建一個新的項目,復制原項目,并改為新項目名 -->
          ? <target name="new" description="creates a new project with the specified name">
          ??? <echo level="info">
          ????? +----------------------------------------------------------+
          ????? |??? -- Welcome to the AppDemo New Application Wizard! --? |
          ????? |????????????????????????????????????????????????????????? |
          ????? | To create a new application, please answer the following |
          ????? | questions.?????????????????????????????????????????????? |
          ????? +----------------------------------------------------------+
          ??? </echo>
          ??? <echo/>
          ?
          ??? <!-- 提示用戶輸入新建的項目名 -->
          ??? <input message="What would you like to name your application [myapp]?"
          ?????????? addproperty="app.name" defaultvalue="myapp"/>
          ?
          ??? <echo level="info">
          ????? Creating new application named '${app.name}'...
          ??? </echo>
          ??? <copy todir="../${app.name}">
          ????? <fileset dir="${basedir}">
          ??????? <exclude name="${lib.dir}/*.txt"/>
          ????? </fileset>
          ??? </copy>
          ?
          ??? <!-- 替換應用名 -->
          ??? <replaceregexp flags="g">
          ????? <regexp pattern="message"/>
          ????? <substitution expression="${app.name}"/>
          ????? <fileset dir="../${app.name}">
          ??????? <include name="**"/>
          ??????? <exclude name="**/*.jar"/>
          ????? </fileset>
          ??? </replaceregexp>
          ? </target>
          </project>

          ??????? 3、webapp.properties文件
          src.dir=src
          build.dir=WebRoot
          webpage.dir=${build.dir}/webpage
          webinf.dir=${build.dir}/webinf
          lib.dir=${webinf.dir}/lib
          classes.dir=${webinf.dir}/classes

          ??????? 4、tomcatTasks.properties文件
          deploy=org.apache.catalina.ant.DeployTask
          install=org.apache.catalina.ant.InstallTask
          list=org.apache.catalina.ant.ListTask
          reload=org.apache.catalina.ant.ReloadTask
          remove=org.apache.catalina.ant.RemoveTask
          resources=org.apache.catalina.ant.ResourcesTask
          roles=org.apache.catalina.ant.RolesTask
          start=org.apache.catalina.ant.StartTask
          stop=org.apache.catalina.ant.StopTask
          undeploy=org.apache.catalina.ant.UndeployTask

          ??????? 5、tomcat.properties文件
          tomcat.server=localhost
          tomcat.manager.url=http://${tomcat.server}/manager
          tomcat.username=admin
          tomcat.password=

          posted on 2006-08-05 10:18 水秀清靈 閱讀(850) 評論(1)  編輯  收藏 所屬分類: 學習筆記

          FeedBack:
          # re: 在開發中使用ant
          2006-08-10 06:45 | 楓中玎玲
          小巫不錯哈,ant都看的差不多了,呵呵
          過段時間我也要學ant老,到時少不了問你問題哦
          ^_^  回復  更多評論
            
          主站蜘蛛池模板: 泗洪县| 宜川县| 达尔| 响水县| 梁河县| 霍山县| 尼勒克县| 汤原县| 惠水县| 大关县| 威宁| 高平市| 浦东新区| 龙川县| 巴中市| 永川市| 察隅县| 郓城县| 和林格尔县| 聊城市| 灌云县| 当雄县| 高淳县| 定边县| 崇明县| 盐源县| 锡林郭勒盟| 陆川县| 嘉义市| 哈尔滨市| 贞丰县| 两当县| 平泉县| 屏南县| 阿拉尔市| 天峻县| 图木舒克市| 忻州市| 锡林郭勒盟| 苏州市| 调兵山市|