简体   繁体   English

Ant + Tomcat部署“无法创建任务或类型部署”

[英]Ant + Tomcat deploy “failed to create task or type deploy”

I'm inheriting a project I need to maintain and trying to get the Ant deployment to Tomcat working on my localhost. 我继承了一个我需要维护的项目,并试图将Ant部署到在我的本地主机上工作的Tomcat。 When I run the deploy task, I get the following errors: 运行部署任务时,出现以下错误:

BUILD FAILED
/.../build.xml:69: Problem: failed to create task or type deploy
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.

I've tried looking around at others having the same problem, and found that commonly issues were in relation to CLASSPATH and missing catalina-ant.jar. 我尝试查看其他有相同问题的人,发现常见问题与CLASSPATH有关,并且缺少catalina-ant.jar。

I added catalina-ant.jar to a folder in my project, called lib-exec, and inside my build.xml, these jars are loaded with: 我将catalina-ant.jar添加到了项目中的一个名为lib-exec的文件夹中,并且在我的build.xml中,这些jar加载了:

<path id="project.classpath">
    <fileset dir="${libDirectory}" includes="**/*.jar" />
    <fileset dir="${extLibDirectory}" includes="**/*.jar" />
</path>

and ${extLibDirectory} is defined as: $ {extLibDirectory}定义为:

<property name="extLibDirectory" location="ext-lib" />

My setup is as follows: 我的设置如下:

  • MAC OS X 10.8.4 MAC OS X 10.8.4
  • Tomcat 7.0.42.0 (installed via Homebrew) Tomcat 7.0.42.0(通过Homebrew安装)
  • Java 1.6.0_51 Java 1.6.0_51
  • Apache Ant 1.8.4 Apache Ant 1.8.4

I tried running the ant deploy task from the command line, and also added 我尝试从命令行运行ant deploy任务,并且还添加了

export CLASSPATH=$CLASSPATH:/usr/local/Cellar/tomcat/7.0.42/libexec/lib

to *~/.bash_profile* to attempt to include catalina-ant.jar this way, but nothing seems to work. 到*〜/ .bash_profile *以尝试通过这种方式包含catalina-ant.jar,但是似乎没有任何效果。

Any ideas what I'm messing up? 有什么想法我搞砸吗?

In addition to including the Tomcat classes in the Ant classpath, you need to define the "deploy" task to have Ant recognize it in the build.xml file, using the taskdef task (place it at the top of build.xml). 除了在Ant类路径中包含Tomcat类之外,您还需要使用taskdef任务(将其放置在build.xml的顶部)定义“部署”任务,以使Ant在build.xml文件中识别它。

Defining paths and properties inside build.xml is completely irrelevant to the classpath (when build.xml is processed the JVM is already running). 在build.xml中定义路径和属性与类路径完全无关(当处理build.xml时,JVM已经在运行)。

Putting a folder in the classpath is likely useless (you need to include in the classpath the jar archives in that folder instead). 将文件夹放在类路径中可能没有用(您需要在该类路径中包含该文件夹中的jar存档)。

Moreover, there's no guarantee that Ant cares for the CLASSPATH environment variable; 而且,不能保证Ant会关心CLASSPATH环境变量。 you have to inspect, and possibly change, the Ant launch script. 您必须检查并可能更改Ant启动脚本。

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

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