How to use Axis2 codegen ANT task

Apache Axis2 code generator tool provides a very useful custom ANT task. All of the command line code generation options are available with the ANT task as well.
Lets see how a simple client side code generation is done using the ANT task.

Pre-requisites:
Install Apache Axis2 -1.3 or higher
Install Apache ANT-1.7 or higher

Step 1

Create a directory and start to create a build.xml inside that as given below. (eg:- C:\temp\build.xml)

<project name="CodegenExample" default="codegen" basedir=".">

<path id="axis2.classpath">
<fileset dir="C:\axis2\axis2-1.4\lib">
<include name="**/*.jar" />
</fileset>
</path>

<target name="codegen">

<taskdef name="axis2-wsdl2java"
classname="org.apache.axis2.tool.ant.AntCodegenTask"
classpathref="axis2.classpath"/>

<axis2-wsdl2java
wsdlfilename="C:\test\your.wsdl"
output="C:\output" />
</target>

</project>

If you are familiar with ANT, you should be able to understand this simple build script easily. We use the path referenced as "axis2.classpath" to add Axis2 library jars which are placed at AXIS2_HOME/lib (In our example, C:\Axis2\Axis2-1.4\lib)

Axis2 codegen ant task is implemented by the org.apache.axis2.tool.ant.AntCodegenTask class. Therefore we refer to that inside a taskdef as given in "taskdef name="axis2-wsdl2java"

wsdlfilename attribute is equivalent to the -uri option in wsdl2 java command line tool and output is similar to -o option.

Replace the values of wsdlfilename according to your wsdl location.

Step 2
Open a command prompt and go to the directory where you saved the above build.xml.
Type 'ant'

The generated stub classes will be saved in the specified out put directory.

Comments

yuvakumarr said…
Hi
Thanks for your nice blog with tips on axis2. I was trying to generate stub classes for mscrm wsdl, using axis2, and followed your sample build.xml. I am getting the following exception...

C:\TEMP\axistest\build.xml:17: org.apache.axis2.wsdl.codegen.CodeGenerationExcep
tion: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException

Could you pl suggest what am I doing wrong here.

Regards

Yuva
Charitha said…
Hi Yuva,
Thanks for your feedback.
Were you able to generate code successfully with wsdl2java.bat tool?
It seems the error is related to your WSDL. if possible, please post your wsdl to uoccharitha@gmail.com

regards
Charitha
yuvakumarr said…
Hi Charitha,

thanks for your reply. No, I am not able to generate the code. I will post the wsdl (2 files) to the email id you have given.

thanks for your help.

Regards

Yuva
yuvakumarr said…
Hi Charitha,

By mistake, I have specified as 2 wsdl files instead of one file. I have sent one WSDL file.

Regards
yuva
Charitha said…
Helo Yuva,
Your wsdl has the following message;
<wsdl:message name="DeleteSoapIn">
<wsdl:part name="entityName" element="tns:entityName" />
<wsdl:part name="id" element="tns:id" /&ht;
</wsdl:message>

As you can see, there are two parts used in this message.
In document style if there are more than one part for the message then
the part to be used should be specified in the binding section.
So, you should modify bindings according to this rule.
e.g:-
<wsdl:input>
<soap:body part="
entityName" use="literal"/>
<soap:header message="tns:DeleteCallerId" part="CallerId" use="literal"/>
</wsdl:input>
yuvakumarr said…
Thanks. I will verify / fix the issue. thanks for your help.

Regards

Yuva
Anonymous said…
God bless you!I really agree with your opinions.Also,there are some new fashion things here,gillette razor blades.gillette mach3 razor bladesfor men.As for ladies,gillette venus razor blades must the best gift for you in summer,gillette fusion blades are all the best choice for you.
http://gilletterazor.blog.drecom.jp
http://www.getablog.net/ColumbiaJackets
http://crystal888.edublogs.org
http://blog.qlep.com/blog.php/gillette
http://chinaclothes.net
Unknown said…
Hello,

I use the org.apache.axis2.tool.ant.AntCodegenTask to produce the server and client side of my service. Everything worked fine with SUN's JDK.

But when I tried to change to IBM's JDK(Java(TM) SE Runtime Environment (build pwi3260sr8fp1-20100624_01(SR8 FP1))) it does not create some of the getters/setters of my objects and build breaks.

Have you ever faced such a problem?

Thanks

Popular posts from this blog

Working with HTTP multipart requests in soapUI

Common mistakes to avoid in WSO2 ESB - 1 - "org.apache.axis2.AxisFault: The system cannot infer the transport information from the URL"

How to deploy JSR181 annotated class in Apache Axis2