简体   繁体   English

Tomcat 6中取消部署任务的问题

[英]Problem with Undeploy Task in Tomcat 6

I am using Tomcat 6, Apache Ant 1.7.1 and JDK 1.6 on OS X Snow Leopard... 我在OS X Snow Leopard上使用Tomcat 6,Apache Ant 1.7.1和JDK 1.6 ...

Created the following build script and supporting property files: 创建以下构建脚本和支持属性文件:

(1) build.xml (1)build.xml

<?xml version="1.0"?>
<project name="${project.name}" default="deploy" basedir=".">
    <property file="build.properties"/>
    <property file="admin.properties"/>

    <taskdef file="tomcatTasks.properties">
      <classpath>
        <pathelement path="${tomcat.home}/lib/catalina-ant.jar"/>
      </classpath>
    </taskdef>

    <target name="prepare">
       <mkdir dir="${webapp.build.dir}" />
       <mkdir dir="${webapp.build.dir}/WEB-INF" />
       <mkdir dir="${webapp.build.dir}/WEB-INF/lib" />
       <mkdir dir="${webapp.build.dir}/WEB-INF/classes" />
    </target>

    <target name="static" depends="prepare">
       <!-- Copy web files -->
       <copy todir="${webapp.build.dir}/">
           <fileset dir="web" />
       </copy>
       <!-- Copy webapp configuration files -->
       <copy todir="${webapp.build.dir}/WEB-INF/">
          <fileset dir="etc" />
       </copy>
       <!-- Copy properties files -->
       <copy todir="${webapp.build.dir}/WEB-INF/classes">
         <fileset dir="props" />
       </copy>
       <!-- Copy jar files -->
       <copy todir="${webapp.build.dir}/WEB-INF/lib/">
          <fileset dir="lib" />
       </copy>
    </target>

    <target name="compile" depends="static">
       <javac srcdir="src"
           destdir="${webapp.build.dir}/WEB-INF/classes/"
           deprecation="off" debug="on" optimize="off">
           <classpath>
               <!-- Include all JAR files in my local library -->
               <fileset dir="lib">
                  <include name="*.jar"/>
               </fileset>
               <!-- Include all common libraries in Tomcat -->
               <fileset dir="${tomcat.home}/lib">
                   <include name="*.jar"/>
               </fileset>
           </classpath>
       </javac>
    </target>

    <target name="deploy" depends="compile">
       <jar jarfile="${build.dir}/${webapp.name}.war" basedir="${webapp.build.dir}" />
       <!-- Copy the newly built WAR file into the deployment directory -->
       <copy file="${build.dir}/${webapp.name}.war" todir="${tomcat.deployment.dir}" />
    </target>

    <target name="clean" description="Clears all generated files, including build directories, distributables, and documentation.">
       <delete dir="${build.dir}"/>
    </target>

    <target name="package">
       <jar jarfile="${build.dir}/${webapp.name}.war" basedir="${webapp.build.dir}" />
    </target>

    <target name="install" description="Install application in Tomcat" depends="package">
        <deploy url="${tomcat.manager.url}"
            username="${tomcat.username}"
            password="${tomcat.password}"
            path="/${webapp.name}"
            war="file:${tomcat.deployment.dir}/${webapp.name}.war"/>
    </target>

    <target name="undeploy" depends="clean" description="Remove application in Tomcat">
        <undeploy url="${tomcat.manager.url}"
              username="${tomcat.username}"
              password="${tomcat.password}"
              path="/${webapp.name}"/>
    </target>
</project>

(2) admin.properties: (2)admin.properties:

tomcat.server=localhost
tomcat.manager.url=http://${tomcat.server}:8080/manager
tomcat.username=admin
tomcat.password=admin

(3) build.properties : (3)build.properties

project.name=myproject
build.dir=./build

# Web app properties for the project
webapp.name=myproject
webapp.build.dir=${build.dir}/${webapp.name}
webapp.virtual.host=localhost
webapp.meta.dir=${webapp.build.dir}/META-INF

# Tomcat properties
tomcat.home=/Users/myuser/DevTools/Java/tomcat/apache-tomcat-6.0.20
tomcat.deployment.dir=${tomcat.home}/webapps

(4) tomcatTasks.properties : (4)tomcatTasks.properties

# Tomcat Task 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-users.xml : (5)tomcat-users.xml

When I run the deploy target, everything works (it places myproject.war) underneath $CATALINA_HOME/webapps... 当我运行部署目标时,一切正常(它将myproject.war放在$ CATALINA_HOME / webapps下面)......

However, when I run the undeploy target, I get the following error message: 但是,当我运行undeploy目标时,我收到以下错误消息:

Problem : 问题

Buildfile: /Users/myuser/work/myproject/build.xml
Trying to override old definition of datatype resources
clean:
    [delete] Deleting directory /Users/myuser/work/myproject/build
undeploy:

BUILD FAILED
/Users/myuser/work/myproject/build.xml:83: java.io.IOException: Server returned HTTP response code: 403 for URL: http://localhost:8080/manager/undeploy?path=/myproject

Total time: 170 milliseconds

Would really appreciate it if someone could tell me what I am doing wrong... 如果有人能告诉我我做错了什么,真的很感激...

Thank you for taking the time to read this... 感谢您抽出时间来阅读...

Happy programming. 快乐的编程。

It's failing because the Tomcat manager application is returning an HTTP status code 403 which means Forbidden. 它失败了,因为Tomcat管理器应用程序返回HTTP状态代码403,这意味着禁止。 So access is being denied. 因此访问被拒绝。

When I googled your question I found your post on JavaRanch which includes your tomcat-users.xml file (not included here). 当我用Google搜索你的问题时,我在JavaRanch上发现了你的帖子,其中包括你的tomcat-users.xml文件(此处不包括在内)。 I see that there is no user with the manager role which is required to run the undeploy task. 我看到没有运行undeploy任务所需的具有manager角色的用户。 Try adding the manager role to your admin user. 尝试将manager角色添加到admin用户。

<role rolename="manager"/>
<user username="admin" password="admin" roles="admin,manager"/> 

From the Tomcat docs : 来自Tomcat文档

To enable access to the Manager web application, you must either create a new username/password combination and associate the role name manager with it, or add the manager role to some existing username/password combination. 要启用对Manager Web应用程序的访问,您必须创建新的用户名/密码组合并将角色名称管理器与其关联,或将管理员角色添加到某些现有的用户名/密码组合。

If you're wondering why your deploy task seems to be working when your undeploy task does not, it's because the deploy task doesn't appear to be using the manager application for its deployment. 如果你想知道为什么你的deploy任务在你的undeploy任务没有工作时似乎正常工作,那是因为deploy任务似乎没有使用管理器应用程序进行部署。 Instead it's simply copying the war to the target directory. 相反,它只是将war复制到目标目录。

Please try to add the role manager-script for the tomcat user you are using. 请尝试为您正在使用的tomcat用户添加角色manager-script

eg 例如

<role rolename="manager-script"/>
<user username="admin" password="admin" roles="manager-script"/>

The complete user entry in tomcat 7.0 user config. tomcat 7.0用户配置中的完整用户条目。

<role rolename="tomcat"/>
<role rolename="manager"/>
<role rolename="manager-script"/>
<role rolename="manager-gui"/>
<role rolename="standard"/>
  <user username="admin" password="admin" roles="tomcat,manager,standard,manager-script,manager-gui"/>
</tomcat-users>

Most of time people miss the first role. 大多数时候人们会错过第一个角色。 stop and restart the server and you would be good. 停止并重新启动服务器,你会很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM