【问题标题】:How can I deploy war in Tomcat 6如何在 Tomcat 6 中部署战争
【发布时间】:2010-01-22 18:56:06
【问题描述】:

我使用过 Jboss,部署是通过将 war 放到部署文件夹中来实现的。但是当我将我的战争项目设置为 Tomcat 服务器时,eclipse 声称它正在部署战争,但我在 webapps 文件夹中看不到我的战争。我的战争的网址是什么?在 jboss 中,我可以将应用程序 url 添加到 jboss-web.xml,所以当我将应用程序路径设置为 jboss-web.xml 时,我可以从 http://localhost:8080/my_app_path_in_jboss_web.xml/ 找到我的应用程序。

【问题讨论】:

  • 在 tomcat 6 中的过程与在 jboss 中使用的过程相同,只需删除 war 文件,服务器会自动部署它。问题可能出在您的 eclipse 配置中。
  • 您使用的是 Windows 7 还是 vista?

标签: java deployment tomcat


【解决方案1】:

我一直将 WAR 部署到 webapps 目录而没有问题,大概每天大约 25 次。你不应该有任何问题。如果您想通过各种方式进行更多控制,请自行部署目录,但这很可能需要重新启动。

【讨论】:

    【解决方案2】:

    使用 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>
    

    【讨论】:

      【解决方案3】:

      如果我理解正确,您已通过添加新服务器将 eclipse 配置为使用 Tomcat。在这种情况下,eclipse 将 war 文件部署在工作空间内的文件夹中,而不是 $TOMCAT_HOME/webapps。我不记得头顶上 Eclipse 工作区文件夹中的路径 - 它应该是包含 tmp、服务器、...的东西。

      【讨论】:

        【解决方案4】:

        您已经在 eclipse 中添加了 Tomcat 服务器,eclipse 在您的工作空间中运行 WAR 文件。 Eclipse 不使用您的 %TOMCAT_HOME%。为了能够在 webapps 文件夹中看到您的 WAR,只需将其放在那里。然后你就可以从 localhost 运行战争了。

        【讨论】:

          猜你喜欢
          • 2013-09-14
          • 1970-01-01
          • 2011-12-01
          • 1970-01-01
          • 2012-04-14
          • 2020-09-24
          • 2015-10-28
          • 1970-01-01
          • 2018-08-30
          相关资源
          最近更新 更多