找不到 taskdef 类 org.apache.catalina.ant.InstallTask [英] taskdef class org.apache.catalina.ant.InstallTask cannot be found

查看:53
本文介绍了找不到 taskdef 类 org.apache.catalina.ant.InstallTask的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Eclipse 中,我的 build.xml 收到 5 个警告:

taskdef class.org.apache.catalina.ant.InstallTask​​ 找不到taskdef class.org.apache.catalina.ant.ListTask找不到taskdef class.org.apache.catalina.ant.ReloadTask找不到找不到 taskdef class.org.apache.catalina.ant.StartTask找不到 taskdef class.org.apache.catalina.ant.StopTask

我已经设置了以下系统环境变量(Windows 7)

ANT_HOME: C:\apache-ant-1.8.4CATALINA_HOME: C:\apache-tomcat-7.0.29JAVA_HOME: C:\Program Files\Java\jdk1.6.0_34并将 %ANT_HOME%/bin 添加到 PATH

我还将 catalina-ant.jar 添加到 C:\apache-ant-1.8.4\lib

代码的更多部分:

<!-- 我们需要 Tomcat 的 Catalina jars --><!-- * 对于其他应用服务器-检查文档--><fileset dir="${appserver.lib}"><include name="catalina-ant.jar"/></文件集></路径><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>

怎么了?

解决方案

我认为只提到 CATALINA_HOME 是行不通的.您需要将 catalina-ant jars 放到 Ant 的类路径中.在 tomcat 7 中,有 4 个用于此目的的 jar,而在早期版本中只有一个 jar.请关注此链接.

引用自链接,

<块引用>

首先,请确保 Tomcat 管理器已配置为供卡特琳娜-蚂蚁.确保 manager-script 包含在角色中TOMCAT_HOME/conf/tomcat-users.xml 中的用户之一.为了例子:

<user name="admin" password="s3cr£t" roles="manager-gui,manager-script"/></tomcat-users>

<块引用>

用于 Tomcat 6 的 Catalina-Ant 被封装在单个 JAR 文件中.Catalina-Ant for Tomcat 7 需要四个 JAR 文件.一个来自TOMCAT_HOME/bin:

tomcat-juli.jar

<块引用>

以及来自 TOMCAT_HOME/lib 的三个:

catalina-ant.jartomcat-coyote.jartomcat-util.jar

<块引用>

至少有三种方法可以让 Ant 使用 JAR:

  • 将 JAR 复制到 ANT_HOME/lib 文件夹中.然后 Ant 就会找到它们.
  • 将 JAR 复制到您签入源控制系统的项目中的文件夹中.Ant 然后需要一个路径 ID 来找到它们:

<fileset dir="${catalina-ant-dir}"><include name="catalina-ant.jar"/><include name="tomcat-coyote.jar"/><include name="tomcat-util.jar"/><include name="tomcat-juli.jar"/></文件集></路径>

<块引用>

其中 catalina-ant-dir 是包含 JAR 的目录.这样你不需要在您构建的每台机器上修改 Ant 安装在.直接从 Tomcat 7 安装访问 JAR.蚂蚁然后需要路径 ID 才能找到它们:

<fileset dir="${appserver.lib}"><include name="catalina-ant.jar"/><include name="tomcat-coyote.jar"/><include name="tomcat-util.jar"/></文件集><fileset dir="${appserver.home}/bin"><include name="tomcat-juli.jar"/></文件集></路径>

<块引用>

其中 appserver.lib 是 Tomcat 7 的 lib 目录的路径和appserver.home 是 Tomcat 顶级安装目录的路径.这样,您构建的每个机器都需要 Tomcat 7.

我个人的偏好是以上 2.

现在您的 Ant 脚本可以看到您需要的 Catalina-Ant JAR告诉它有哪些任务可用.这些是大多数(如果不是全部)Ant 可用的任务.

<taskdef name="catalina-list" classname="org.apache.catalina.ant.ListTask" classpathref="catalina-ant-classpath"/><taskdef name="catalina-reload" classname="org.apache.catalina.ant.ReloadTask" classpathref="catalina-ant-classpath"/><taskdef name="catalina-findleaks" classname="org.apache.catalina.ant.FindLeaksTask" classpathref="catalina-ant-classpath"/><taskdef name="catalina-resources" classname="org.apache.catalina.ant.ResourcesTask" classpathref="catalina-ant-classpath"/><taskdef name="catalina-start" classname="org.apache.catalina.ant.StartTask" classpathref="catalina-ant-classpath"/><taskdef name="catalina-stop" classname="org.apache.catalina.ant.StopTask" classpathref="catalina-ant-classpath"/><taskdef name="catalina-undeploy" classname="org.apache.catalina.ant.UndeployTask" classpathref="catalina-ant-classpath"/>

<块引用>

最后,您需要一组实际完成工作的任务.虽然,正如您在上面看到的,有一些任务我只倾向于使用以下任务:

<catalina-stop url="${tomcat.manager.url}"用户名="${tomcat.username}"密码="${tomcat.password}"path="/${webapp.name}"失败错误=假"/></目标><目标名称 = "start-webapp"><catalina-start url="${tomcat.manager.url}"用户名="${tomcat.username}"密码="${tomcat.password}"path="/${webapp.name}"/></目标><target name = "undeploy-webapp"><catalina-undeploy url="${tomcat.manager.url}"用户名="${tomcat.username}"密码="${tomcat.password}"path="/${webapp.name}"失败错误=假"/></目标><目标名称 = "deploy-webapp"><catalina-deploy url="${tomcat.manager.url}"用户名="${tomcat.username}"密码="${tomcat.password}"path="/${webapp.name}"war="file:${war.file}"/></目标>

<块引用>

tomcat.manager.url 是 Tomcat 管理器所在的 URL.这是从 Tomcat 6 到 Tomcat 7 的另一个变化.通常这会为:http://:8080/manager/text.

Tomcat.usernameTomcat.password 是用户名和密码Tomcat 管理器.

webapp.name 是您所在的 Tomcat 应用程序的名称正在部署.

war.file 是您正在部署的 Tomcat 应用程序的 WAR 的路径文件.

In Eclipse I am getting 5 warnings for my build.xml:

taskdef class.org.apache.catalina.ant.InstallTask cannot be found
taskdef class.org.apache.catalina.ant.ListTaskcannot be found
taskdef class.org.apache.catalina.ant.ReloadTaskcannot be found
taskdef class.org.apache.catalina.ant.StartTask cannot be found
taskdef class.org.apache.catalina.ant.StopTask cannot be found

I've set up the following system environment variables (Windows 7)

ANT_HOME: C:\apache-ant-1.8.4
CATALINA_HOME: C:\apache-tomcat-7.0.29
JAVA_HOME: C:\Program Files\Java\jdk1.6.0_34
and have added %ANT_HOME%/bin to PATH

edit: I've also added catalina-ant.jar into C:\apache-ant-1.8.4\lib

More parts of the code:

<!-- 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>

What's wrong?

解决方案

I think only mentioning the CATALINA_HOME does not work. You need to put the catalina-ant jars to the Ant's class path. In tomcat 7, there 4 jars for this purpose while there was only single jar for this in earlier versions. Please follow this link.

As quoted from the link,

To start with, make sure Tomcat manager is configured for use by Catalina-Ant. Make sure that manager-script is included in the roles for one of the users in TOMCAT_HOME/conf/tomcat-users.xml. For example:

<tomcat-users>
    <user name="admin" password="s3cr£t" roles="manager-gui,manager-script"/>
</tomcat-users>

Catalina-Ant for Tomcat 6 was encapsulated within a single JAR file. Catalina-Ant for Tomcat 7 requires four JAR files. One from TOMCAT_HOME/bin:

tomcat-juli.jar

and three from TOMCAT_HOME/lib:

catalina-ant.jar
tomcat-coyote.jar
tomcat-util.jar

There are at least three ways of making the JARs available to Ant:

  • Copy the JARs into the ANT_HOME/lib folder. Then Ant will just find them.
  • Copy the JARs to a folder within your project that you check into your source control system. Ant then needs a path id to find them:

<path id="catalina-ant-classpath">
   <fileset dir="${catalina-ant-dir}">
      <include name="catalina-ant.jar"/>
      <include name="tomcat-coyote.jar"/>
      <include name="tomcat-util.jar"/>
      <include name="tomcat-juli.jar"/>
   </fileset>
</path>

Where catalina-ant-dir is the directory with the JARs in. This way you don’t need to modify the Ant installation on every machine you build on. Access the JARs directly from your Tomcat 7 installation. Ant then needs a path id to find them:

<path id="catalina-ant-classpath">
    <fileset dir="${appserver.lib}">
           <include name="catalina-ant.jar"/>
           <include name="tomcat-coyote.jar"/>
           <include name="tomcat-util.jar"/>
        </fileset>
    <fileset dir="${appserver.home}/bin">
               <include name="tomcat-juli.jar"/>
    </fileset>
</path>

Where appserver.lib is the path to Tomcat 7’s lib directory and appserver.home is the path to Tomcat’s top level installed directory. This way Tomcat 7 is required on every box you build on.

My personal preference is for 2 above.

Now that your Ant script can see the Catalina-Ant JARs you need to tell it what tasks are available. These are most if not all of the tasks that are available to Ant.

<taskdef name="catalina-deploy" classname="org.apache.catalina.ant.DeployTask" classpathref="catalina-ant-classpath"/>
<taskdef name="catalina-list" classname="org.apache.catalina.ant.ListTask" classpathref="catalina-ant-classpath"/>
<taskdef name="catalina-reload" classname="org.apache.catalina.ant.ReloadTask" classpathref="catalina-ant-classpath"/>
<taskdef name="catalina-findleaks" classname="org.apache.catalina.ant.FindLeaksTask" classpathref="catalina-ant-classpath"/>
<taskdef name="catalina-resources" classname="org.apache.catalina.ant.ResourcesTask" classpathref="catalina-ant-classpath"/>
<taskdef name="catalina-start" classname="org.apache.catalina.ant.StartTask" classpathref="catalina-ant-classpath"/>
<taskdef name="catalina-stop" classname="org.apache.catalina.ant.StopTask" classpathref="catalina-ant-classpath"/>
<taskdef name="catalina-undeploy" classname="org.apache.catalina.ant.UndeployTask" classpathref="catalina-ant-classpath"/>

Finally you need a set of tasks that actually do the work. Although, as you can see above, there are a few tasks I only tend to use the following ones:

<target name = "stop-webapp">
       <catalina-stop url="${tomcat.manager.url}"
                         username="${tomcat.username}"
                         password="${tomcat.password}"
                         path="/${webapp.name}"
                         failonerror="false"/>
</target>

<target name = "start-webapp">
    <catalina-start url="${tomcat.manager.url}"
                       username="${tomcat.username}"
                       password="${tomcat.password}"
                       path="/${webapp.name}"/>
</target>

<target name = "undeploy-webapp">
    <catalina-undeploy url="${tomcat.manager.url}"
                          username="${tomcat.username}"
                          password="${tomcat.password}"
                          path="/${webapp.name}"
                          failonerror="false"/>
</target>

<target name = "deploy-webapp">
    <catalina-deploy url="${tomcat.manager.url}"
                        username="${tomcat.username}"
                        password="${tomcat.password}"
                        path="/${webapp.name}"
                        war="file:${war.file}"/>
</target>

tomcat.manager.url is the URL where Tomcat manager lives. This is another of the changes from Tomcat 6 to Tomcat 7. Usually this will be: http://:8080/manager/text.

Tomcat.username and Tomcat.password are the user name and password for Tomcat manager.

webapp.name is the name of the Tomcat application that you are deploying.

war.file is the path the Tomcat application you are deploying’s WAR file.

这篇关于找不到 taskdef 类 org.apache.catalina.ant.InstallTask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆