欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-07-13 08:14:09
...
3招解决ant构建时任务找不到(taskdef cann't be found)的问题

[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命令行指定:
[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指定:
<?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:
[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的实现。