简体   繁体   English

找不到taskdef类org.apache.catalina.ant.InstallTask

[英]taskdef class org.apache.catalina.ant.InstallTask cannot be found

In Eclipse I am getting 5 warnings for my build.xml: 在Eclipse中,我的build.xml收到5个警告:

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) 我已经设置了以下系统环境变量(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 编辑:我还将catalina-ant.jar添加到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? 怎么了?

In tomcat 7 InstallTask is replaced by DeployTask. 在tomcat 7中,InstallTask​​被DeployTask取代。

change your declaration like 改变你的声明

old

<taskdef name="install" classname="org.apache.catalina.ant.InstallTask">
    <classpath refid="catalina-ant-classpath"/>
</taskdef>

with

 <taskdef name="install" classname="org.apache.catalina.ant.DeployTask"> 
  <classpath refid="catalina-ant-classpath"/> 
 </taskdef>

I think only mentioning the CATALINA_HOME does not work. 我想只提到CATALINA_HOME是行不通的。 You need to put the catalina-ant jars to the Ant's class path. 你需要把catalina-ant罐子放到Ant的类路径上。 In tomcat 7, there 4 jars for this purpose while there was only single jar for this in earlier versions. 在tomcat 7中,为此目的有4个罐子,而在早期版本中只有一个罐子。 Please follow this link . 请点击此链接

As quoted from the link, 从链接引用,

To start with, make sure Tomcat manager is configured for use by Catalina-Ant. 首先,确保配置Tomcat管理器以供Catalina-Ant使用。 Make sure that manager-script is included in the roles for one of the users in TOMCAT_HOME/conf/tomcat-users.xml . 确保manager-script包含在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. 用于Tomcat 6的Catalina-Ant封装在单个JAR文件中。 Catalina-Ant for Tomcat 7 requires four JAR files. 用于Tomcat 7的Catalina-Ant需要四个JAR文件。 One from TOMCAT_HOME/bin : 一个来自TOMCAT_HOME/bin

tomcat-juli.jar

and three from TOMCAT_HOME/lib : 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: 至少有三种方法可以使Ant可用于JAR:

  • Copy the JARs into the ANT_HOME/lib folder. 将JAR复制到ANT_HOME/lib文件夹中。 Then Ant will just find them. 然后Ant就会找到它们。
  • Copy the JARs to a folder within your project that you check into your source control system. 将JAR复制到项目中您检入源控制系统的文件夹中。 Ant then needs a path id to find them: 然后Ant需要一个路径ID来找到它们:
<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. 其中catalina-ant-dir是JAR所在的目录。这样,您无需在构建的每台计算机上修改Ant安装。 Access the JARs directly from your Tomcat 7 installation. 直接从Tomcat 7安装访问JAR。 Ant then needs a path id to find them: 然后Ant需要一个路径ID来找到它们:

<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. 其中appserver.lib是Tomcat 7的lib目录的路径, appserver.home是Tomcat顶级安装目录的路径。 This way Tomcat 7 is required on every box you build on. 这样,您构建的每个盒子都需要Tomcat 7。

My personal preference is for 2 above. 我个人的偏好是2以上。

Now that your Ant script can see the Catalina-Ant JARs you need to tell it what tasks are available. 现在您的Ant脚本可以看到Catalina-Ant JAR,您需要告诉它哪些任务可用。 These are most if not all of the tasks that are available to Ant. 这些是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. tomcat.manager.url是Tomcat管理器所在的URL。 This is another of the changes from Tomcat 6 to Tomcat 7. Usually this will be: http://:8080/manager/text . 这是从Tomcat 6到Tomcat 7的另一个变化。通常这将是: http://:8080/manager/text

Tomcat.username and Tomcat.password are the user name and password for Tomcat manager. Tomcat.usernameTomcat.password是Tomcat管理器的用户名和密码。

webapp.name is the name of the Tomcat application that you are deploying. webapp.name是要部署的Tomcat应用程序的名称。

war.file is the path the Tomcat application you are deploying's WAR file. war.file是您正在部署WAR文件的Tomcat应用程序的路径。

Guess you might have to do this change, since there is no more details in your question 猜猜你可能不得不做这个改变,因为你的问题没有更多细节

<fileset dir="${appserver.home}/common/lib">
<include name="servlet*.jar"/>
</fileset> 

I beleive you might have the above settings in your build.xml Please, change ${appserver.home} to the directory that contains the tomcat installation 我相信你可能在build.xml中有上述设置请将$ {appserver.home}更改为包含tomcat安装的目录

<fileset dir="C:/Program Files/Apache Software Foundation/Tomcat 5.5/common/lib">
<include name="servlet*.jar"/>
</fileset> 

In tomcat 7, org.apache.catalina.ant contains a set of Task that can be used to interact with the Manager application to deploy, undeploy, list, reload, start and stop web applications from a running instance of Tomcat. 在tomcat 7中,org.apache.catalina.ant包含一组Task,可用于与Manager应用程序交互,以从正在运行的Tomcat实例部署,取消部署,列出,重新加载,启动和停止Web应用程序。 Replacing InstallTask with DeployTask will solve build problem. 用DeployTask替换InstallTask​​将解决构建问题。

<taskdef name="install" classname="org.apache.catalina.ant.DeployTask">
        <classpath refid="catalina-ant-classpath"/>
    </taskdef>
    <taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
        <classpath refid="catalina-ant-classpath"/>`enter code here`
    </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>

If you are using eclipes then you need to change your ant_home location by following below steps, navigate to window>prefrances>Ant>runtime>classpath>AntHome click on anthome button and provide your anthome directory path. 如果你正在使用eclipes,那么你需要按照以下步骤更改你的ant_home位置,导航到window> prefrances> Ant> runtime> classpath> AntHome点击anthome按钮并提供你的anthome目录路径。

and to solv ur problem u need to copy catalina-ant.jar inside anthome/lib folder 并解决你的问题,你需要复制anthome / lib文件夹中的catalina-ant.jar

Thanks, Sharad 谢谢,沙拉德

Try out the following, it will solve your problem: 试试以下内容,它将解决您的问题:

1) Click Eclipse menu Window > Preferences
2) Click Ant > Runtime
3) Under Classpath tab, select Ant Home Entries and click button Add External JARs
4) Browse and open $ECLIPSE_HOME/plugins/org.apache.ant_myscrum/lib/catalina-ant.jar
5) Click Apply and OK button

按照第3号指令操作

按照第4号指令操作

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

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