Problem-failed to create task or type xjc

Problem-failed to create task or type xjc

Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any / declarations have taken place.

Answer: If you are trying to create web service client and using ant build task to create wsdl client using XJC tool which comes with JDK distribution then you will have to add taskdef of it as sample shown below:

<project name="SpringWebserviceTemplate" default="generate.client.bindings" basedir="." >
    
    <description>Generate web service client using spring WS template</description>
    
    <property name="root" value="." />
    <property name="lib"  location="${root}/lib"/>  
    
    <path id="classpathid_location">
            <fileset dir="${lib}/main" includes="*.jar"/>
    </path>   
    
    <!-- http://jaxb.java.net/2.2.6/docs/ch04.html#tools-xjc-ant-task -->
    <taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
        <classpath refid="classpathid_location"/>
    </taskdef>
    

    <!--    Generate Targets to generate wsdl client -->
        <target name="generate.client.bindings" description="- -> Generate XML binding artifacts" >
                    <!-- http://jaxb.java.net/2.2.6/docs/ch04.html#tools-xjc-ant-task -->       
                    <xjc    destdir="${basedir}/src" 
                            package="com.javahonk.webClient.currencyconvertor"
                            removeOldOutput="yes"
                    >
                        <arg value="-verbose" />
                        <arg value="-wsdl" />
                        <arg value="${basedir}/conf/xml/wsdl/currencyConvertor.wsdl" />
                    </xjc>
        </target>
        
        <!--    Compile Targets     -->

    </project>

Please note exception will be thrown if taskdef is missing form build file.

Leave a Reply

Your email address will not be published. Required fields are marked *

I am not Robot *