跳到主要內容

Ant deploy war file to Tomcat server

雖然離開Java有段時間了
不過還是難忘Java在一些地方的好處
這邊簡介如何透過ANT來作Tomcat的部署
Tomcat主機資訊如下:

Tomcat version: 6.0.32
Server IP: xxx.xxx.xxx.xxx
Tomcat Port: 8080
Script Deployer: tomcat (password: tomcatpassword)

特殊設定:
1. ant需要把catalina-ant.jar放到ant家目錄的lib中
2. tomcat-user.xml(位於$TOMCAT_HOME/conf下)需要加入manager-script的角色

下面是deploy的ant script
裡面有hard code部署時候需要的
1. application name: /TestWeb2
2. server deploy endpoint: http://xxx.xxx.xxx.xxx:8080/manager
3. deployer username, password: tomcat / tomcatpassword
當然,這些變數也可以透過-Dkeyname=keyvalue的方式在執行時候帶入

build.xml
<project name="My Application" default="compile" basedir=".">
  <!-- Configure the context path for this application -->
  <property name="path"     value="/TestWeb2"/>

  <!-- Configure properties to access the Manager application -->
  <property name="url"      value="http://xxx.xxx.xxx.xxx:8080/manager"/>
  <property name="username" value="tomcat"/>
  <property name="password" value="tomcatpassword"/>

  <!-- Configure the custom Ant tasks for the Manager application -->
  <taskdef name="deploy"    classname="org.apache.catalina.ant.DeployTask"/>
  <taskdef name="list"      classname="org.apache.catalina.ant.ListTask"/>
  <taskdef name="reload"    classname="org.apache.catalina.ant.ReloadTask"/>
  <taskdef name="resources" classname="org.apache.catalina.ant.ResourcesTask"/>
  <taskdef name="roles"     classname="org.apache.catalina.ant.RolesTask"/>
  <taskdef name="start"     classname="org.apache.catalina.ant.StartTask"/>
  <taskdef name="stop"      classname="org.apache.catalina.ant.StopTask"/>
  <taskdef name="undeploy"  classname="org.apache.catalina.ant.UndeployTask"/>

  <target name="deploy" description="Install web application" >
    <deploy url="${url}" username="${username}" password="${password}" path="${path}" war="${war}"/>
  </target>

  <target name="reload" description="Reload web application">
    <reload  url="${url}" username="${username}" password="${password}" path="${path}"/>
  </target>

  <target name="undeploy" description="Remove web application">
    <undeploy url="${url}" username="${username}" password="${password}" path="${path}"/>
  </target>
</project>


執行範例:
Do Deploy
○ → ant -Dwar=/Users/simonsu/Desktop/TestWeb2.war deploy
Buildfile: /Users/simonsu/opt/tomcat-deployer/build.xml
Trying to override old definition of datatype resources

deploy:
   [deploy] OK - Deployed application at context path /TestWeb2

BUILD SUCCESSFUL
Total time: 0 seconds


Do Reload
○ → ant reload
Buildfile: /Users/simonsu/opt/tomcat-deployer/build.xml
Trying to override old definition of datatype resources

reload:
   [reload] OK - Reloaded application at context path /TestWeb2

BUILD SUCCESSFUL
Total time: 0 seconds


Do Undeploy
○ → ant undeploy
Buildfile: /Users/simonsu/opt/tomcat-deployer/build.xml
Trying to override old definition of datatype resources

undeploy:
 [undeploy] OK - Undeployed application at context path /TestWeb2

BUILD SUCCESSFUL
Total time: 0 seconds

參考資料:
http://tomcat.apache.org/tomcat-6.0-doc/manager-howto.html#Executing_Manager_Commands_With_Ant

這個網誌中的熱門文章

Oracle LISTAGG

同事介紹的一個Oracle的好用查詢:LISTAGG
SELECT A.GROUP_ID,A.KEY, LISTAGG(A.VALUE,'; ')WITHINGROUP(ORDERBYA.VALUE)as GG  fromSYS_PROPERTIESaGROUP byA.GROUP_ID,A.KEY
LISTAGG可以將group後的結果會總顯示於一個欄位 上述SQL原本A.VALUE會是一個row一個row的排列 使用LISTAGG之後,可以將A.VALUE顯示在同一個row中 並且可以指定間隔符號(在此設定為';') 針對某一些報表查詢非常有用唷 :D

Flashback Query

感謝我的好友提供的: 在Oracle好用的指令...
Flashback Query: 讓異動過的資料表回到歷史時間點 Step 1. è
show parameter undo_retention  PS: 這個參數顯示系統上設定歷史保留時間(ex: 900 = 900秒) Step 2. è CREATETABLE XXXXX_0815 ASSELECT *  FROM XXXXXASOFTIMESTAMPTO_TIMESTAMP('2011-08-15 12:00:00','YYYY-MM-DD HH24:MI:SS');
PS: 透過as of timestamp方式取出該時間點的表格資料

Xoom 3.2 Upgrade

雖然Xoom早已經更新到3.2 但是台灣遲遲沒有更新版本@@ 終於按奈不住好奇心了... XDA上找到給604(台版Xoom)的3.2版本ROM(美版的) 動手刷拉~~ 出奇的順利阿... 下面是兩個相關網址:
http://forum.xda-developers.com/showthread.php?t=1165998
http://forum.xda-developers.com/showthread.php?t=1080963
我這邊是刷第二各網址下載的3.2 ROM(http://www.mediafire.com/?adsa081m3z8uykd) 3.1的就沒去測拉... 也沒有再去破解(遲早的ㄅ:P)
使用心得: 1. 順~比3.0操頻還順 2. 原生就支援micro-sd 3. 目前看是不支援USB...缺憾@@ 4. 因為美版的關係,所以有Books跟Videos兩個APP,但是因為網路地區的關係不能用就是了... 5. 沒有原生中文輸入法,不過對我沒差...我都用Google拼音 :D