Search code examples
javaantapache-axisaxiswsdl2java

How to add extraClasses option to Ant script when calling java2wsdl?


I'd like to pass extraClasses parameter when I generate java2wsdl. Here is my Ant task:

<target name="rews.all" depends="xews.aar">
    <echo message="${axis2.classpath}" />
    <delete file="${build.dir}/wsdl/XEWS.wsdl" />
    <taskdef name="java2wsdl"
             classname="org.apache.ws.java2wsdl.Java2WSDLTask"
             classpathref="axis2.classpath">                 
    </taskdef>
    <java2wsdl className="com.dd.xews.XEWS"
               outputLocation="${build.dir}/wsdl/"
               targetNamespace="http://xews.dd.com/"
               schemaTargetNamespace="http://xews.dd.com">
        <classpath>
            <pathelement path="${axis2.classpath}"/>
            <pathelement location="${build.dir}/classes"/>
            <pathelement location="${vendor.dir}/AWS/lib/aws-java-sdk-1.2.1.jar"/>
        </classpath>            
    </java2wsdl>
    <copy todir="${build.dir}/" file="${build.dir}/wsdl/XEWS.wsdl"/>
</target>

Tried everything but no luck.

Does anyone know the syntax? How do I add extraClasses here?

Test1 (failed)

This failed with error java2wsdl doesn't support the "extraClasses" attribute:

<java2wsdl className             ="com.dd.xews.XEWS"
           outputLocation        ="${build.dir}/wsdl/"
           targetNamespace       ="http://xews.dd.com/"
           schemaTargetNamespace ="http://xews.dd.com"
           extraClasses          ="com.dd.xews.XEWS.Emailer.java">  
</java2wsdl>

How to find out which attributes java2wsdl Ant task does support?

My Axis2 version is 1.5.4.


Solution

  • Here's a link to the source code of Ant task: Java2WSDLTask.

    #setExtraClasses accepts String parameter, and then tries to split it using comma delimiter. So try passing something like

    <extraClasses>com.test.Class1,com.test.Class2</extraClasses>

    EDIT

    This will not work in older versions of Axis2 (to be more precise -- versions prior 1.6.0). It's because of 'extraClasses' attribute was specified as an array-type, which is obviously not supported as Ant task attribute. You can find all the details in this JIRA issue: AXIS2-4634: Ant task Java2WSDLTask does not allow the use of extraClasses

    The easiest way to make it work is to upgrade Axis2 JARs to a newer 1.6.x version. If you are stuck with Axis2 version for some project-specific reasons (I don't see there should be any), you could take the source code of Java2WSDLTask from the newer version (see link to GrepCode above), and make a copy of this task in your project (you'll have to use different class name, or package), then use it as an Ant task just like you are using it currently. Except for it will be possible to use 'extraClasses' attribute.