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

在用ant编译项目时,有时会碰到build.xml中所定义的任务找不到的问题:

点击(此处)折叠或打开

  1. [root@tivu25 test]# ant -f build.xml local_war
  2. Buildfile: build.xml

  3. local_war:

  4. BUILD FAILED
  5. /home/haoqf/software/APM/test/build.xml:18: taskdef class com.ibm.team.build.ant.task.LogPublisherTask cannot be found

  6. Total time: 0 seconds
这是因为ant在当前java的classpath中找不到类LogPublisherTaskLogPublisherTask由 org.apache.tools.ant.Task派生而来),这时候需要重新指定当前的classpath,让它包含LogPublisherTask所属jar库或者class的路径。有三种方法:
1. 在ant命令行指定:

点击(此处)折叠或打开

  1. [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指定:

点击(此处)折叠或打开

  1. ?xml version="1.0" encoding="UTF-8"?>

  2. project name="BVT_CVT" default="local_war">
  3.     
  4.      target name="local_war">
  5.         taskdef name="logPublisher" classname="com.ibm.team.build.ant.task.LogPublisherTask">
  6.         classpath>
  7.             pathelement location="/home/haoqf/software/RTC/RTC-BuildSystem-Toolkit-Linux-3.0iFix1/jazz/buildsystem/buildtoolkit/"/>
  8.             fileset dir="/home/haoqf/software/RTC/RTC-BuildSystem-Toolkit-Linux-3.0iFix1/jazz/buildsystem/buildtoolkit/">
  9.                 include name="**/*.jar"/>
  10.             /fileset>
  11.         /classpath>
  12.         /taskdef>
  13.     
  14.         logPublisher repositoryAddress="${repositoryAddress}"    />

  15.      /target>
  16. /project>
3. 设定当前环境变量CLASSPATH:

点击(此处)折叠或打开

  1. [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的实现。





上一篇:VSTO学习笔记(十四)Excel数据透视表与PowerPivot


下一篇:JAVA中字符串比较equals()和equalsIgnoreCase()的区别