簡體   English   中英

如何在Tomcat 6中部署war

[英]How can I deploy war in Tomcat 6

我使用了Jboss並通過將war放到deploy文件夾來進行部署。 但是當我將我的戰爭項目設置為Tomcat服務器時,eclipse聲稱它正在部署戰爭,但我無法在webapps文件夾中看到我的戰爭。 我的戰爭是什么網址? 在jboss中我可以將應用程序URL添加到jboss-web.xml,所以當我將應用程序路徑設置為jboss-web.xml時,我可以從http:// localhost:8080 / my_app_path_in_jboss_web.xml /找到我的應用程序。

我總是將WAR部署到webapps dir而沒有問題,可能每天約25次。 你不應該有任何問題。 如果您希望通過各種方式進行更多控制,請自行部署目錄,但這很可能需要重新啟動。

使用ant簡化了任務。 這是一個用於部署到tomcat 6的ant build.xml文件。(注意,我不是這個的原始作者,但我忘記了從哪里得到它)

<project name="provisioning" basedir="." default="usage">
<property file="build.properties"/>

<property name="src.dir" value="src"/>
<property name="web.dir" value="war"/>
<property name="build.dir" value="${web.dir}/WEB-INF/classes"/>
<property name="name" value="provisioning"/>

<path id="master-classpath">
    <fileset dir="${web.dir}/WEB-INF/lib">
        <include name="*.jar"/>
    </fileset>
    <!-- We need the servlet API classes: -->
    <!--  * for Tomcat 5/6 use servlet-api.jar -->
    <!--  * for other app servers - check the docs -->
    <fileset dir="${appserver.lib}">
        <include name="servlet*.jar"/>
    </fileset>
    <pathelement path="${build.dir}"/>
</path>

<target name="usage">
    <echo message=""/>
    <echo message="${name} build file"/>
    <echo message="-----------------------------------"/>
    <echo message=""/>
    <echo message="Available targets are:"/>
    <echo message=""/>
    <echo message="build     --> Build the application"/>
    <echo message="deploy    --> Deploy application as directory"/>
    <echo message="deploywar --> Deploy application as a WAR file"/>
    <echo message="install   --> Install application in Tomcat"/>
    <echo message="reload    --> Reload application in Tomcat"/>
    <echo message="start     --> Start Tomcat application"/>
    <echo message="stop      --> Stop Tomcat application"/>
    <echo message="list      --> List Tomcat applications"/>
    <echo message=""/>
</target>

<target name="build" description="Compile main source tree java files">
    <mkdir dir="${build.dir}"/>
    <javac destdir="${build.dir}" source="1.6" target="1.6" debug="true"
           deprecation="false" optimize="false" failonerror="true">
        <src path="${src.dir}"/>
        <classpath refid="master-classpath"/>
    </javac>
</target>

<target name="deploy" depends="build" description="Deploy application">
    <copy todir="${deploy.path}/${name}" preservelastmodified="true">
        <fileset dir="${web.dir}">
            <include name="**/*.*"/>
        </fileset>
    </copy>
</target>

<target name="deploywar" depends="build" description="Deploy application as a WAR file">
    <war destfile="${name}.war"
         webxml="${web.dir}/WEB-INF/web.xml">
        <fileset dir="${web.dir}">
            <include name="**/*.*"/>
        </fileset>
    </war>
    <copy todir="${deploy.path}" preservelastmodified="true">
        <fileset dir=".">
            <include name="*.war"/>
        </fileset>
    </copy>
</target>

<path id="catalina-ant-classpath">
    <!-- We need the Catalina jars for Tomcat -->
    <!--  * for other app servers - check the docs -->
    <fileset dir="${appserver.lib}">
        <include name="catalina-ant.jar"/>
    </fileset>
</path>

<taskdef name="install" classname="org.apache.catalina.ant.InstallTask">
    <classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
    <classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="list" classname="org.apache.catalina.ant.ListTask">
    <classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="start" classname="org.apache.catalina.ant.StartTask">
    <classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="stop" classname="org.apache.catalina.ant.StopTask">
    <classpath refid="catalina-ant-classpath"/>
</taskdef>

<target name="install" description="Install application in Tomcat">
    <install url="${tomcat.manager.url}"
             username="${tomcat.manager.username}"
             password="${tomcat.manager.password}"
             path="/${name}"
             war="${name}"/>
</target>

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

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

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

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

如果我理解正確,您已通過添加新服務器將eclipse配置為使用Tomcat。 在這種情況下,eclipse將war文件部署在工作區內的文件夾中,而不是$ TOMCAT_HOME / webapps。 我不記得eclipse的工作區文件夾中的路徑從頭頂 - 它應該是包含tmp,server,...的東西

您已在eclipse中添加了Tomcat服務器,eclipse在您的工作區中運行WAR文件。 Eclipse不使用%TOMCAT_HOME%。 為了能夠在webapps文件夾中查看您的WAR,只需將其放入其中即可。 然后你將從localhost運行戰爭。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM