---
title: "3招解决ant构建时任务找不到(taskdef cann't be found)的问题 "
author: "open023"
date: "2016-07-05T14:43:30Z"
tags: []
categories: ["开源软件"]
slug: "3-ant-taskdef-cann-t-be-found"
draft: false
lastmod: "2016-07-05T14:43:30Z"
id: 2309319
url: "https://open023.iteye.com/blog/2309319"
---

3招解决ant构建时任务找不到(taskdef cann't be found)的问题 

```java
[root@tivu25 test]# ant -f build.xml local_war
Buildfile: build.xml

local_war:

BUILD FAILED
/home/haoqf/software/APM/test/build.xml:18: taskdef class com.ibm.team.build.ant.task.LogPublisherTask cannot be found

Total time: 0 seconds
```

这是因为ant在当前java的classpath中找不到类LogPublisherTask（LogPublisherTask由 org.apache.tools.ant.Task派生而来），这时候需要重新指定当前的classpath，让它包含LogPublisherTask所属jar库或者class的路径。有三种方法：
1. 在ant命令行指定：

```java

[root@tivu25 test]# ant -f build.xml local_war -lib /home/haoqf/software/RTC/RTC-BuildSystem-Toolkit-Linux-3.0iFix1/jazz/buildsystem/buildtoolkit/

```

2. 在build.xml指定：

```java
<?xml version="1.0" encoding="UTF-8"?>

<project name="BVT_CVT" default="local_war">
    
     <target name="local_war">
        <taskdef name="logPublisher" classname="com.ibm.team.build.ant.task.LogPublisherTask">
        <classpath>
            <pathelement location="/home/haoqf/software/RTC/RTC-BuildSystem-Toolkit-Linux-3.0iFix1/jazz/buildsystem/buildtoolkit/"/>
            <fileset dir="/home/haoqf/software/RTC/RTC-BuildSystem-Toolkit-Linux-3.0iFix1/jazz/buildsystem/buildtoolkit/">
                <include name="**/*.jar"/>
            </fileset>
        </classpath>
        </taskdef>
    
        <logPublisher repositoryAddress="${repositoryAddress}"    />

     </target>
</project>
```

3. 设定当前环境变量CLASSPATH：

```java
[root@tivu25 test]# export CLASSPATH=$CLASSPATH:/home/haoqf/software/RTC/RTC-BuildSystem-Toolkit-Linux-3.0iFix1/jazz/buildsystem/buildtoolkit/com.ibm.team.build.toolkit_2.2.0.v20110308_0258.jar
```

其中com.ibm.team.build.toolkit_2.2.0.v20110308_0258.jar包含了类LogPublisherTask的实现。