failed to create task or type war-builder in workl

2019-08-28 08:15发布

问题:

I am using workklight 6.2 and wrote following ant task to build war file on linux machine command line.

<taskdef resource="com/worklight/ant/defaults.properties">
    <classpath>
        <pathelement location="opt/IBM/Worklight/WorklightServer/worklight-ant-builder.jar"/>
    </classpath>
</taskdef>

<target name="build-war">        
    <war-builder projectfolder="${basedir}"
                 destinationfolder="bin/"
                 warfile="bin/MyProject.war"
                 classesFolder="classes-folder"/>
</target>

When I execute the task with following command "ant -f /opt/MyWS/MyProject/build.xml "build-war" it gives me following error :

Problem: failed to create task or type war-builder
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.

ANT_HOME is set to "/opt/IBM/Worklight/tools/apache-ant-1.8.4". When I execute the same task in eclipse, it just works fine.

回答1:

It seems the path to the jar file is not set correctly (you missed the root slash):

<taskdef resource="com/worklight/ant/defaults.properties">
    <classpath>
      <pathelement location="/opt/IBM/Worklight/WorklightServer/worklight-ant-builder.jar"/>
    </classpath>
</taskdef>