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

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

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

    捕風之巢

    統(tǒng)計

    留言簿(3)

    java友情鏈接

    閱讀排行榜

    評論排行榜

    Ant+Tomcat自動部署

    今天研究對象是Ant,用于對msms系統(tǒng)進行Tomcat的自動部署。

    遇到一個怪問題,百思不得其解:
    通過ant depoly可以把msms.war部署到tomcat上。當然,要求這時候webapps下面沒有msms目錄。
    看tomcat的紀錄,加載msms.war正常,網頁也可以打開。

    通過ant undeploy,可以把msms卸載。Tomcat顯示:
    Undeploying context [/msms]
    正常卸載了。問題是,去看webapps目錄下面,居然有一個msms目錄的殘骸,里面保留的目錄是
    WEB-INF\lib
    有以下幾個文件殘留著:
    commons-digester.jar
    commons-validator.jar
    struts.jar

    這時候msms目錄也無法手工刪除,必須停掉tomcat后才能刪除。

    我裝的tomcat是5.5。不知道是否還有人遇到過這種情況,我反正是暈了。

    build.properties文件如下:
    tomcat.dir=C:/ApacheGroup/Tomcat5.5
    tomcat.webapps=C:/ApacheGroup/Tomcat5.5/webapps
    tomcat.manager.url=http://localhost:8080/manager
    tomcat.manager.username=admin
    tomcat.manager.password=xxxxxxxx

    build.xml文件如下:
    <?xml version="1.0"?>
    <project name="msms" default="compile" basedir=".">
    ??? <!-- Ant Tomcat Task Definition -->
    ??? <taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask">
    ??? ??? <classpath>
    ??? ??? ??? <path location="${tomcat.dir}/server/lib/catalina-ant.jar" />
    ??? ??? </classpath>
    ??? </taskdef>

    ??? <taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask">
    ??? ??? <classpath>
    ??? ??? ??? <path location="${tomcat.dir}/server/lib/catalina-ant.jar" />
    ??? ??? </classpath>
    ??? </taskdef>

    ??? <taskdef name="install" classname="org.apache.catalina.ant.InstallTask">
    ??? ??? <classpath>
    ??? ??? ??? <path location="${tomcat.dir}/server/lib/catalina-ant.jar" />
    ??? ??? </classpath>
    ??? </taskdef>

    ??? <taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
    ??? ??? <classpath>
    ??? ??? ??? <path location="${tomcat.dir}/server/lib/catalina-ant.jar" />
    ??? ??? </classpath>
    ??? </taskdef>

    ??? <taskdef name="list" classname="org.apache.catalina.ant.ListTask">
    ??? ??? <classpath>
    ??? ??? ??? <path location="${tomcat.dir}/server/lib/catalina-ant.jar" />
    ??? ??? </classpath>
    ??? </taskdef>

    ??? <taskdef name="start" classname="org.apache.catalina.ant.StartTask">
    ??? ??? <classpath>
    ??? ??? ??? <path location="${tomcat.dir}/server/lib/catalina-ant.jar" />
    ??? ??? </classpath>
    ??? </taskdef>

    ??? <taskdef name="stop" classname="org.apache.catalina.ant.StopTask">
    ??? ??? <classpath>
    ??? ??? ??? <path location="${tomcat.dir}/server/lib/catalina-ant.jar" />
    ??? ??? </classpath>
    ??? </taskdef>

    ??? <property name="build" value="build" />
    ??? <property name="dist" value="dist" />
    ??? <property name="src" value="src/java" />
    ??? <property name="test" value="src/test" />
    ??? <property name="war-config" value="src/config" />
    ??? <property name="report" value="report" />
    ??? <property name="lib" value="lib" />
    ??? <property name="web" value="web" />
    ??? <property name="meta" value="meta" />
    ??? <property name="context-path" value="${ant.project.name}" />
    ??? <property file="build.properties" />

    ??? <path id="build.classpath">
    ??? ??? <fileset file="${lib}/*.jar" />
    ??? ??? <fileset dir="${tomcat.dir}/common/lib">
    ??? ??? ??? <include name="*.jar" />
    ??? ??? </fileset>
    ??? ??? <fileset dir="${tomcat.dir}/common/endorsed">
    ??? ??? ??? <include name="*.jar" />
    ??? ??? </fileset>
    ??? ??? <pathelement path="${build}" />
    ??? </path>

    ??? <!-- Hibernate Tool Task Definition -->
    ??? <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="build.classpath" />
    ???
    ??? <target name="clean">
    ??? ??? <echo message="Cleaning up the build and dist directories" />
    ??? ??? <delete dir="${build}" />
    ??? ??? <mkdir dir="${build}" />
    ??? ??? <delete dir="${dist}" />
    ??? ??? <mkdir dir="${dist}" />
    ??? </target>

    ??? <target name="copy-resources">
    ??? ??? <copy todir="${build}">
    ??? ??? ??? <fileset dir="${src}">
    ??? ??? ??? ??? <exclude name="**/*.java" />
    ??? ??? ??? ??? <exclude name="**/*.hbm.xml" />
    ??? ??? ??? </fileset>
    ??? ??? </copy>
    ??? </target>

    ??? <target name="compile" depends="copy-resources">
    ??? ??? <javac destdir="${build}" srcdir="${src}:${test}">
    ??? ??? ??? <classpath refid="build.classpath" />
    ??? ??? </javac>
    ??? </target>

    ??? <target name="initdb" depends="compile">
    ??? ??? <hibernatetool destdir="${build}">
    ??? ??? ??? <classpath>
    ??? ??? ??? ??? <path location="${build}" />
    ??? ??? ??? </classpath>
    ??? ??? ??? <annotationconfiguration configurationfile="src/java/hibernate.cfg.xml" />

    ??? ??? ??? <hbm2ddl create="true" />
    ??? ??? </hibernatetool>
    ??? </target>

    ??? <target name="run" depends="compile">
    ??? ??? <java fork="true" classname="cn.ac.rcpa.msms.tools.ProjectManager" classpathref="build.classpath">
    ??? ??? ??? <classpath path="${build}" />
    ??? ??? ??? <arg value="${action}" />
    ??? ??? ??? <arg value="${project}" />
    ??? ??? ??? <arg value="${description}" />
    ??? ??? </java>
    ??? </target>

    ??? <target name="test" depends="compile" description="run junit test">
    ??? ??? <delete dir="${report}" />
    ??? ??? <mkdir dir="${report}" />
    ??? ??? <junit dir="." fork="true" printsummary="on" haltonfailure="false" failureproperty="tests.failed" showoutput="true">
    ??? ??? ??? <classpath refid="build.classpath" />
    ??? ??? ??? <formatter type="brief" />
    ??? ??? ??? <batchtest todir="${report}">
    ??? ??? ??? ??? <fileset dir="${build}">
    ??? ??? ??? ??? ??? <include name="**/*Test.*" />
    ??? ??? ??? ??? ??? <include name="**/Test*.*" />
    ??? ??? ??? ??? </fileset>
    ??? ??? ??? </batchtest>
    ??? ??? </junit>
    ??? ??? <fail if="tests.failed">
    ????? ***********************************************************
    ????? **** One or more tests failed! Check the output ... ****
    ????? ***********************************************************
    ??? </fail>
    ??? </target>

    ??? <target name="create-war" depends="clean, compile" description="build release war">
    ??? ??? <echo message="creation the WAR file...${context-path}.war" />
    ??? ??? <war destfile="${dist}/${context-path}.war" webxml="${meta}/web.xml">
    ??? ??? ??? <classes dir="${build}">
    ??? ??? ??? ??? <exclude name="**/*Test.*" />
    ??? ??? ??? ??? <exclude name="**/Test*.*" />
    ??? ??? ??? ??? <exclude name="hibernate.cfg.xml" />
    ??? ??? ??? </classes>
    ??? ??? ??? <lib dir="${lib}" />
    ??? ??? ??? <fileset dir="${web}" />
    ??? ??? ??? <zipfileset dir="${war-config}" prefix="WEB-INF/classes" />
    ??? ??? </war>
    ??? ??? <!--??? ??? <scp file="${dist}/${context-path}.war" todir="root:${password}@172.16.1.20:/usr/local/tomcat/webapps" trust="true" /> -->
    ??? </target>

    ??? <target name="deploy" description="Install application in Tomcat">
    ??? ??? <deploy url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="/${context-path}" localWar="file:${dist}/${context-path}.war" />
    ??? </target>

    ??? <target name="undeploy" description="Remove application in Tomcat" if="already.deployed">
    ??? ??? <undeploy url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="/${context-path}" />
    ??? </target>

    ??? <target name="reload" description="Reload application in Tomcat">
    ??? ??? <reload url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="/${context-path}" />
    ??? </target>

    ??? <target name="start" description="Start Tomcat application">
    ??? ??? <start url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="/${context-path}" />
    ??? </target>

    ??? <target name="stop" description="Stop Tomcat application">
    ??? ??? <stop url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="/${context-path}" />
    ??? </target>

    ??? <target name="list" description="List Tomcat applications">
    ??? ??? <list url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" />
    ??? </target>

    ??? <target name="deploy-application" description="Compile the web application...">
    ??? ??? <echo message="Undeploying the application only if it's deployed..." />
    ??? ??? <available file="${tomcat.webapps}/${context-path}.war" property="already.deployed" />
    ??? ??? <antcall target="undeploy" />
    ??? ??? <antcall target="create-war" />
    ??? ??? <antcall target="deploy" />
    ??? </target>
    </project>


    只有Windows上才會有的問題,
    創(chuàng)建META-INF目錄, 在目錄里新建context.xml,加入如下內容

    <?xml version="1.0" encoding="UTF-8"?>
    <Context reloadable="true" antiResourceLocking="true">
    </Context>

    昨天的錯誤至今無法修正,即使重裝了Tomcat也不行。

    不過,deploy到兩臺linux服務器上倒都成功了。
    ??? <taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask">
    ??? ??? <classpath>
    ??? ??? ??? <path location="${tomcat.dir}/server/lib/catalina-ant.jar" />
    ??? ??? </classpath>
    ??? </taskdef>

    ??? <taskdef name="list" classname="org.apache.catalina.ant.ListTask">
    ??? ??? <classpath>
    ??? ??? ??? <path location="${tomcat.dir}/server/lib/catalina-ant.jar" />
    ??? ??? </classpath>
    ??? </taskdef>

    ??? <target name="deploy-web" description="Install application in Local Tomcat">
    ??? ??? <echo message="deploying to web ..." />
    ??? ??? <deploy url="http://172.16.1.20:8080/manager" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="/${context-path}" war="file:${dist}/${context-path}.war" update="true" />
    ??? </target>

    ??? <target name="list-web">
    ??? ??? <echo message="list web tomcat ..." />
    ??? ??? <list url="http://172.16.1.20:8080/manager" username="${tomcat.manager.username}" password="${tomcat.manager.password}" />
    ??? </target>


    這里跟昨天的代碼有一點不一樣:
    1、localWar改成了war。
    原來更新遠程服務器的時候,總是顯示更新成功,但是到webapps目錄下總是沒有相應的war文件,通過調用
    ant list-web
    發(fā)現,有一個context-path是dist/msms,而且是stop狀態(tài)。哦,原來localWar的意思不是指開發(fā)的機器的local path,而是指把這個war被寫到服務器的什么地方。改成war就正常了。

    2、不需要判斷是否已經deploy進而調用undeploy了,直接通過update="true"更新就可以了。

    posted on 2006-11-23 08:59 捕風 閱讀(17785) 評論(1)  編輯  收藏 所屬分類: java高級

    評論

    # re: Ant+Tomcat自動部署 2007-10-24 16:03 paoding

    徹底解決Ant在Tomcat進行卸載部署undeploy時不能刪除jar文件的問題

    首先有一種解決辦法,就是在應用下的META-INF下新建context.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <Context reloadable="true" antiResourceLocking="true" antiJARLocking="true">
    </Context>

    這種方法在重復進行多次deploy、undeploy時的確解決了該問題。但是如果在deploy和undeploy之間執(zhí)行如下的webtest任務,也就是在undeploy前訪問該應用,那么Tomcat就會加載jar文件,再執(zhí)行undeploy時還是不能刪除jar文件,此時似乎Tomcat植入jar根深蒂固了!
    <target name="webtest_login">
    <echo message="WebTest測試"/>
    <exec executable="cmd">
    <arg line="/c webtest.bat -f tools/Java/webtest/login.xml -Dwebtest.home=${tools.webtest}"/>
    <arg line="-Dwebtest.home=${tools.webtest}"/>
    <arg line="-Dhost=${manager.ip}"/>
    <arg line="-Dport=${manager.port}"/>
    <arg line="-Dbasepath=${deploy.name}"/>
    <arg line="-Dresultpath=${report.webtestReport.part}"/>
    <arg line="-Dresultfile=${report.webtestReport.xml.part}"/>
    </exec>
    <xslt in="${report.webtestReport.xml}" out="${report.webtestReport.html}" style="${tools.webtest.reportstyle}" />
    </target>

    有一個辦法可以徹底解決該問題,就是使用xml部署文件來部署應用,不適用war發(fā)布的方式:
    <target name="deploy">
    <echo message="安裝Web應用"/>
    <taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask" classpathref="classpath.catalina"/>
    <deploy url="${manager.url}" username="${manager.username}" password="${manager.password}" path="/${deploy.name}" config="D:\AutoBuilder\build\student\web\context.xml"/>
    </target>

    context.xml描述的項目目錄位于Tomcat外的目錄:
    <Context path="/student" docBase="D:/AutoBuilder/build/student/web" debug="0"/>

    這樣應用程序是指向外界的,不位于Tomcat目錄中,再執(zhí)行undeploy時就沒有這個問題了。而且使用war進行deploy時后臺的錯誤也不會再出現了:
    java.io.FileNotFoundException: webapps\student (The system cannot find the path specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:106)
    at org.apache.catalina.startup.ExpandWar.copyInternal(ExpandWar.java:226)

    BTW,deploy時會在C:\Tomcat 5.5\conf\Catalina\localhost下拷貝生成context.xml,undeploy時會刪除該文件。  回復  更多評論   

    主站蜘蛛池模板: 四虎1515hh永久久免费| 亚欧免费一级毛片| 日本高清免费不卡在线| 亚洲沟沟美女亚洲沟沟| 18勿入网站免费永久| 国产精品亚洲片夜色在线 | 中文无码成人免费视频在线观看| 亚洲成av人片在线观看天堂无码| 精品国产亚洲AV麻豆| 国产精品久久久久影院免费| 真人无码作爱免费视频| 国产成人精品免费直播| 一区二区三区在线免费观看视频 | 精品免费视在线观看| 国产亚洲精品一品区99热| 久操视频免费观看| 亚洲最大在线观看| 免费的涩涩视频在线播放| 青青草97国产精品免费观看| 国产亚洲一区二区三区在线| 污视频在线免费观看| 久久亚洲精品国产亚洲老地址| 日韩a在线观看免费观看| 无码人妻一区二区三区免费视频 | 老司机亚洲精品影院在线观看| 国产成人精品久久亚洲高清不卡 | 中国内地毛片免费高清| 91亚洲va在线天线va天堂va国产| 九九九精品成人免费视频| 色屁屁www影院免费观看视频| 亚洲精品美女久久久久99| 999国内精品永久免费观看| 国产成人综合久久精品亚洲| 亚洲热妇无码AV在线播放| 18禁免费无码无遮挡不卡网站| 精品亚洲成A人在线观看青青| 国产亚洲人成无码网在线观看| 久久久久久久久免费看无码| 人成电影网在线观看免费| 亚洲性无码av在线| 区三区激情福利综合中文字幕在线一区亚洲视频1 |