We have two ways to develop a web service, start with the XML Schema/WSDL contract first followed by the Java code second, or start with Java code first followed by WSDL second, however, the recommended way is to use contract-first mode, then translate the WSDL to the the Java stub code by using wsdl2java utility tool.

wsdl2java - takes a WSDL document and generates fully annotated Java code from which to implement a service. wsdl2java can generate an Ant based makefile to build your application, the following steps will demo how to do.

1. Import the following dependency jars to classpath in Ant.

<file name=”jaxb-xjc.jar”/><!– dependency of cxf –>
<file name=”velocity.jar”/><!– dependency of cxf –>
<file name=”aopalliance.jar”/><!– dependency of cxf –>
<file name=”asm.jar”/><!– dependency of cxf –>
<file name=”cxf.jar”/>
<file name=”FastInfoset.jar”/><!– dependency of cxf –>

2. Use ant target to generate Java code, This below is an example.

<target name="generate_wsdl" depends="init">
        <mkdir dir="${build.gen}"/>
        <java classname="org.apache.cxf.tools.wsdlto.WSDLToJava" fork="true">
            <arg value="-d"/>
            <arg value="${build.gen}"/>
            <arg value="-p"/>
            <arg value="com.asjava>
            <arg value="-ant"/>
            <arg value="${main.res}/asjava.wsdl"/>
                <path refid="main.cp"/>

${build.gen} specifies the directory into which the generated code files are written..
${main.res}/asjava.wsdl specifics the path and name of the WSDL file to use in generating the code
main.cp is the classpath defined and used in ant.
<arg value="com.asjava> specifics the package name to organize these newly generated sources.