| <!DOCTYPE html> |
| <!-- |
| | Generated by Apache Maven Doxia Site Renderer 1.7.4 at 2017-05-06 |
| | Rendered using Apache Maven Fluido Skin 1.6 |
| --> |
| <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| <head> |
| <meta charset="UTF-8" /> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| <meta name="Date-Revision-yyyymmdd" content="20170506" /> |
| <meta http-equiv="Content-Language" content="en" /> |
| <title>Apache Axis2 – Code Generator Tool Guide for Command Line and Ant |
| Task</title> |
| <link rel="stylesheet" href="../css/apache-maven-fluido-1.6.min.css" /> |
| <link rel="stylesheet" href="../css/site.css" /> |
| <link rel="stylesheet" href="../css/print.css" media="print" /> |
| <script type="text/javascript" src="../js/apache-maven-fluido-1.6.min.js"></script> |
| <meta name="generator" content="HTML Tidy for Windows (vers 14 June 2007), see www.w3.org" /><meta http-equiv="content-type" content="" /> </head> |
| <body class="topBarDisabled"> |
| <div class="container-fluid"> |
| <div id="banner"> |
| <div class="pull-left"><a href="http://www.apache.org/" id="bannerLeft"><img src="http://www.apache.org/images/asf_logo_wide.png" alt="Apache Axis2"/></a></div> |
| <div class="pull-right"><a href=".././" id="bannerRight"><img src="../images/axis.jpg" /></a></div> |
| <div class="clear"><hr/></div> |
| </div> |
| |
| <div id="breadcrumbs"> |
| <ul class="breadcrumb"> |
| <li id="publishDate">Last Published: 2017-05-06<span class="divider">|</span> |
| </li> |
| <li id="projectVersion">Version: 1.7.5<span class="divider">|</span></li> |
| <li class=""><a href="http://www.apache.org" class="externalLink" title="Apache">Apache</a><span class="divider">/</span></li> |
| <li class=""><a href="../index.html" title="Axis2/Java">Axis2/Java</a><span class="divider">/</span></li> |
| <li class="active ">Code Generator Tool Guide for Command Line and Ant |
| Task</li> |
| </ul> |
| </div> |
| <div class="row-fluid"> |
| <div id="leftColumn" class="span2"> |
| <div class="well sidebar-nav"> |
| <ul class="nav nav-list"> |
| <li class="nav-header">Axis2/Java</li> |
| <li><a href="../index.html" title="Home"><span class="none"></span>Home</a> </li> |
| <li><a href="../download.html" title="Downloads"><span class="none"></span>Downloads</a> </li> |
| <li><a href="javascript:void(0)" title="Release Notes"><span class="icon-chevron-down"></span>Release Notes</a> |
| <ul class="nav nav-list"> |
| <li><a href="../release-notes/1.6.1.html" title="1.6.1"><span class="none"></span>1.6.1</a> </li> |
| <li><a href="../release-notes/1.6.2.html" title="1.6.2"><span class="none"></span>1.6.2</a> </li> |
| <li><a href="../release-notes/1.6.3.html" title="1.6.3"><span class="none"></span>1.6.3</a> </li> |
| <li><a href="../release-notes/1.6.4.html" title="1.6.4"><span class="none"></span>1.6.4</a> </li> |
| <li><a href="../release-notes/1.7.0.html" title="1.7.0"><span class="none"></span>1.7.0</a> </li> |
| <li><a href="../release-notes/1.7.1.html" title="1.7.1"><span class="none"></span>1.7.1</a> </li> |
| <li><a href="../release-notes/1.7.2.html" title="1.7.2"><span class="none"></span>1.7.2</a> </li> |
| <li><a href="../release-notes/1.7.3.html" title="1.7.3"><span class="none"></span>1.7.3</a> </li> |
| <li><a href="../release-notes/1.7.4.html" title="1.7.4"><span class="none"></span>1.7.4</a> </li> |
| <li><a href="../release-notes/1.7.5.html" title="1.7.5"><span class="none"></span>1.7.5</a> </li> |
| </ul> |
| </li> |
| <li><a href="../modules/index.html" title="Modules"><span class="none"></span>Modules</a> </li> |
| <li><a href="../tools/index.html" title="Tools"><span class="none"></span>Tools</a> </li> |
| <li class="nav-header">Documentation</li> |
| <li><a href="../docs/toc.html" title="Table of Contents"><span class="none"></span>Table of Contents</a> </li> |
| <li><a href="../docs/installationguide.html" title="Installation Guide"><span class="none"></span>Installation Guide</a> </li> |
| <li><a href="../docs/quickstartguide.html" title="QuickStart Guide"><span class="none"></span>QuickStart Guide</a> </li> |
| <li><a href="../docs/userguide.html" title="User Guide"><span class="none"></span>User Guide</a> </li> |
| <li><a href="../docs/jaxws-guide.html" title="JAXWS Guide"><span class="none"></span>JAXWS Guide</a> </li> |
| <li><a href="../docs/pojoguide.html" title="POJO Guide"><span class="none"></span>POJO Guide</a> </li> |
| <li><a href="../docs/spring.html" title="Spring Guide"><span class="none"></span>Spring Guide</a> </li> |
| <li><a href="../docs/webadminguide.html" title="Web Administrator's Guide"><span class="none"></span>Web Administrator's Guide</a> </li> |
| <li><a href="../docs/migration.html" title="Migration Guide (from Axis1)"><span class="none"></span>Migration Guide (from Axis1)</a> </li> |
| <li class="nav-header">Resources</li> |
| <li><a href="../faq.html" title="FAQ"><span class="none"></span>FAQ</a> </li> |
| <li><a href="../articles.html" title="Articles"><span class="none"></span>Articles</a> </li> |
| <li><a href="http://wiki.apache.org/ws/FrontPage/Axis2/" class="externalLink" title="Wiki"><span class="none"></span>Wiki</a> </li> |
| <li><a href="../refLib.html" title="Reference Library"><span class="none"></span>Reference Library</a> </li> |
| <li><a href="../apidocs/index.html" title="Online Java Docs"><span class="none"></span>Online Java Docs</a> </li> |
| <li class="nav-header">Get Involved</li> |
| <li><a href="../overview.html" title="Overview"><span class="none"></span>Overview</a> </li> |
| <li><a href="../svn.html" title="Checkout the Source"><span class="none"></span>Checkout the Source</a> </li> |
| <li><a href="../mail-lists.html" title="Mailing Lists"><span class="none"></span>Mailing Lists</a> </li> |
| <li><a href="../release-process.html" title="Release Process"><span class="none"></span>Release Process</a> </li> |
| <li><a href="../guidelines.html" title="Developer Guidelines"><span class="none"></span>Developer Guidelines</a> </li> |
| <li><a href="../siteHowTo.html" title="Build the Site"><span class="none"></span>Build the Site</a> </li> |
| <li class="nav-header">Project Information</li> |
| <li><a href="../team-list.html" title="Project Team"><span class="none"></span>Project Team</a> </li> |
| <li><a href="../issue-tracking.html" title="Issue Tracking"><span class="none"></span>Issue Tracking</a> </li> |
| <li><a href="http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/" class="externalLink" title="Source Code"><span class="none"></span>Source Code</a> </li> |
| <li><a href="../thanks.html" title="Acknowledgements"><span class="none"></span>Acknowledgements</a> </li> |
| <li class="nav-header">Apache</li> |
| <li><a href="http://www.apache.org/licenses/LICENSE-2.0.html" class="externalLink" title="License"><span class="none"></span>License</a> </li> |
| <li><a href="http://www.apache.org/foundation/sponsorship.html" class="externalLink" title="Sponsorship"><span class="none"></span>Sponsorship</a> </li> |
| <li><a href="http://www.apache.org/foundation/thanks.html" class="externalLink" title="Thanks"><span class="none"></span>Thanks</a> </li> |
| <li><a href="http://www.apache.org/security/" class="externalLink" title="Security"><span class="none"></span>Security</a> </li> |
| </ul> |
| <hr /> |
| <div id="poweredBy"> |
| <div class="clear"></div> |
| <div class="clear"></div> |
| <div class="clear"></div> |
| <div class="clear"></div> |
| <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy"><img class="builtBy" alt="Built by Maven" src="../images/logos/maven-feather.png" /></a> |
| </div> |
| </div> |
| </div> |
| <div id="bodyColumn" class="span10" > |
| <html xmlns="http://www.w3.org/1999/xhtml"> |
| |
| |
| <h1>Code Generator Tool Guide for Command Line and Ant Task</h1> |
| |
| <p>The Code Generator tool consists of a command line version and |
| an Ant Task. This document will list the command line references |
| and Ant task references. Also in detail, this document shows how to |
| build file using custom Ant task and invoking the Code Generator |
| from Ant.</p> |
| |
| <p>This tool is bundled with the <a href="../download.cgi#std-bin">Axis2 Binary |
| Distribution</a>.</p> |
| |
| <div class="section"> |
| <h2><a name="Content"></a>Content</h2> |
| |
| <ul> |
| |
| <li><a href="#intro">Introduction</a></li> |
| |
| <li><a href="#cmdline">Command Line Version</a> |
| |
| <ul> |
| |
| <li><a href="#cmdref">Option Reference</a></li> |
| </ul> |
| </li> |
| |
| <li><a href="#ant">Ant Task</a> |
| |
| <ul> |
| |
| <li><a href="#antref">Ant Task Reference</a></li> |
| |
| <li><a href="#example">Example Build File Using the Custom Ant |
| Task</a></li> |
| |
| <li><a href="#invoking">Invoking the Code Generator From |
| Ant</a></li> |
| </ul> |
| </li> |
| |
| <li><a href="#appendix">Appendix</a></li> |
| </ul> |
| <a name="intro" id="intro"></a> |
| |
| <div class="section"> |
| <h2><a name="Introduction"></a>Introduction</h2> |
| |
| <p>This basic tool is implemented by the WSDL2Code class and just |
| for the convenience in the case of Java (which would be the |
| majority) there is another WSDL2Java class. One can choose to run |
| the main classes directly or use one of the scripts to run the |
| WSDL2Code and WSDL2Java appropriately. (the scripts are found in |
| the bin directory of the <a href="../download.cgi#std-bin">Standard Binary |
| Distribution</a>)</p> |
| <a name="cmdline" id="cmdline"></a> |
| |
| <div class="section"> |
| <h2><a name="Command_Line_Version"></a>Command Line Version</h2> |
| |
| <p>For those users who wish to use the command line version of the |
| tool, this section will be of value.</p> |
| <a name="cmdref" id="cmdref"></a> |
| |
| <div class="section"> |
| <h3><a name="Option_Reference"></a>Option Reference</h3> |
| |
| <p>Usage WSDL2Code <option_reference></p> |
| |
| <p><b>E.g. :- WSDL2Code -uri <Location of WSDL></b></p> |
| |
| <table border="0" class="table table-striped"> |
| <tbody> |
| |
| <tr class="a"> |
| |
| <td width="20%"><b>Short Option</b></td> |
| |
| <td width="20%"><b>Long Option</b></td> |
| |
| <td width="60%"><b>Description</b></td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="b"> |
| |
| <td width="20%">-uri <Location of WSDL></td> |
| |
| <td width="20%">None</td> |
| |
| <td width="60%">WSDL file location. This should point to a WSDL |
| file in the local file system.</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="a"> |
| |
| <td width="20%">-o <output Location></td> |
| |
| <td width="20%">--output <output Location></td> |
| |
| <td width="60%">Output file location. This is where the files would |
| be copied once the code generation is done. If this option is |
| omitted the generated files would be copied to the working |
| directory.</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="b"> |
| |
| <td width="20%">-l <language></td> |
| |
| <td width="20%">--language <language></td> |
| |
| <td width="60%">Output language. Currently the code generator can |
| generate code in Java but it has the ability to be extended to |
| support other languages.</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="a"> |
| |
| <td width="20%">-p <package name></td> |
| |
| <td width="20%">--package <package name></td> |
| |
| <td width="60%">The target package name. If omitted, a default |
| package (formed using the target namespace of the WSDL) will be |
| used.</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="b"> |
| |
| <td width="20%">-a</td> |
| |
| <td width="20%">--async</td> |
| |
| <td width="60%">Generate code only for async style. When this |
| option is used the generated stubs will have only the asynchronous |
| invocation methods. Switched off by default.</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="a"> |
| |
| <td width="20%">-s</td> |
| |
| <td width="20%">--sync</td> |
| |
| <td width="60%">Generate code only for sync style . When this |
| option is used the generated stubs will have only the synchronous |
| invocation methods. Switched off by default. When used with the -a |
| option, this takes precedence.</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="b"> |
| |
| <td width="20%">-t</td> |
| |
| <td width="20%">--test-case</td> |
| |
| <td width="60%">Generates a test case. In the case of Java it would |
| be a JUnit test case.</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="a"> |
| |
| <td width="20%">-ss</td> |
| |
| <td width="20%">--server-side</td> |
| |
| <td width="60%">Generates server side code (i.e. skeletons). |
| Default is off.</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="b"> |
| |
| <td width="20%">-sd</td> |
| |
| <td width="20%">--service-description</td> |
| |
| <td width="60%">Generates the service descriptor (i.e. server.xml). |
| Default is off. Only valid with -ss, the server side code |
| generation option.</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="a"> |
| |
| <td width="20%">-d <databinding></td> |
| |
| <td width="20%">--databinding-method <databinding></td> |
| |
| <td width="60%">Specifies the Databinding framework. Valid values |
| are xmlbeans, adb, jibx, and none. Default is adb.</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="b"> |
| |
| <td width="20%">-g</td> |
| |
| <td width="20%">--generate-all</td> |
| |
| <td width="60%">Generates all the classes. This option is valid |
| only with the -ss (server side code generation) option. When on, |
| the client code (stubs) will also be generated along with the |
| skeleton.</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="a"> |
| |
| <td width="20%">-u</td> |
| |
| <td width="20%">--unpack-classes</td> |
| |
| <td width="60%">Unpack classes. This option specifies whether to |
| unpack the classes and generate separate classes for the |
| databinders.</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="b"> |
| |
| <td width="20%">-sn <service name></td> |
| |
| <td width="20%">--service-name <service name></td> |
| |
| <td width="60%">Specifies the service name to be code generated. If |
| the service name is not specified, then the first service will be |
| picked.</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="a"> |
| |
| <td width="20%">-pn <port name></td> |
| |
| <td width="20%">--port-name <port name></td> |
| |
| <td width="60%">Specifies the port name to be code generated. If |
| the port name is not specified, then the first port (of the |
| selected service) will be picked.</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="b"> |
| |
| <td width="20%">-ns2p</td> |
| |
| <td width="20%">--namespace2package</td> |
| |
| <td width="60%">Specifies a comma separated list of namespaces and |
| packages where the given package will be used in the place of the |
| auto generated package for the relevant namespace. The list will be |
| the format of ns1=pkg1,ns2=pkg2.</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="a"> |
| |
| <td width="20%">-ssi</td> |
| |
| <td width="20%">--serverside-interface</td> |
| |
| <td width="60%">Generate an interface for the service |
| skeleton.</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="b"> |
| |
| <td width="20%">-wv</td> |
| |
| <td width="20%">--wsdl-version</td> |
| |
| <td width="60%">WSDL Version. Valid Options : 2, 2.0, 1.1</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="a"> |
| |
| <td width="20%">-S</td> |
| |
| <td width="20%">--source-folder</td> |
| |
| <td width="60%">Specify a directory path for generated source</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="b"> |
| |
| <td width="20%">-R</td> |
| |
| <td width="20%">--resource-folder</td> |
| |
| <td width="60%">Specify a directory path for generated resources</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="a"> |
| |
| <td width="20%">-em</td> |
| |
| <td width="20%">--external-mapping</td> |
| |
| <td width="60%">Specify an external mapping file</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="b"> |
| |
| <td width="20%">-f</td> |
| |
| <td width="20%">--flatten-files</td> |
| |
| <td width="60%">Flattens the generated files</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="a"> |
| |
| <td width="20%">-uw</td> |
| |
| <td width="20%">--unwrap-params</td> |
| |
| <td width="60%">Switch on un-wrapping</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="b"> |
| |
| <td width="20%">-xsdconfig</td> |
| |
| <td width="20%"></td> |
| |
| <td width="60%">Use XMLBeans .xsdconfig file. Valid only with -d xmlbeans</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="a"> |
| |
| <td width="20%">-ap</td> |
| |
| <td width="20%">--all-ports</td> |
| |
| <td width="60%">Generate code for all ports</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="b"> |
| |
| <td width="20%">-or</td> |
| |
| <td width="20%">--over-ride</td> |
| |
| <td width="60%">Overwrite the existing classes</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="a"> |
| |
| <td width="20%">-b</td> |
| |
| <td width="20%">--backword-compatible</td> |
| |
| <td width="60%">Generate Axis 1.x backword compatible code</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="b"> |
| |
| <td width="20%">-sp</td> |
| |
| <td width="20%">--suppress-prefixes</td> |
| |
| <td width="60%">Suppress namespace prefixes (Optimzation that reduces size of soap request/response)</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="a"> |
| |
| <td width="20%"></td> |
| |
| <td width="20%">--noBuildXML</td> |
| |
| <td width="60%">Don't generate the build.xml in the output directory</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="b"> |
| |
| <td width="20%"></td> |
| |
| <td width="20%">--noWSDL</td> |
| |
| <td width="60%">Don't generate WSDL's in the resources directory</td> |
| |
| <td></td> |
| </tr> |
| |
| <tr class="a"> |
| |
| <td width="20%"></td> |
| |
| <td width="20%">--noMessageReceiver</td> |
| |
| <td width="60%">Don't generate a MessageReceiver in the generated sources</td> |
| |
| <td></td> |
| </tr> |
| </tbody> |
| </table> |
| |
| <p>Apart from these mentioned options one can pass extra options by |
| prefixing them with -E (uppercase). These extra options will be |
| processed by the extensions. The extra options that can be passed |
| are documented separately with the extensions documentation (For |
| example with ADB).</p> |
| <a name="ant" id="ant"></a> |
| </div> |
| <div class="section"> |
| <h2><a name="Ant_Task"></a>Ant Task</h2> |
| |
| <p>The code generator also comes bundled with an Ant task. The ant |
| task is implemented by the org.apache.axis2.tool.ant.AntCodegenTask |
| class. Following are the ant task attributes.</p> |
| <a name="antref" id="antref"></a> |
| |
| <div class="section"> |
| <h3><a name="Ant_Task_Reference"></a>Ant Task Reference</h3> |
| |
| <table border="0" class="table table-striped"> |
| <tbody> |
| |
| <tr class="a"> |
| |
| <td>wsdlfilename</td> |
| |
| <td>WSDL file location. Maps to the -uri option of the command line |
| tool.</td> |
| </tr> |
| |
| <tr class="b"> |
| |
| <td>output</td> |
| |
| <td>Output file location. This is where the files would be copied |
| once the code generation is done. If this option is omitted the |
| generated files would be copied to the working directory. Maps to |
| the -o option of the command line tool.</td> |
| </tr> |
| |
| <tr class="a"> |
| |
| <td>language</td> |
| |
| <td>Output language. Currently the code generator can generate code |
| in Java. Maps to the -l option of the command line tool.</td> |
| </tr> |
| |
| <tr class="b"> |
| |
| <td>packageName</td> |
| |
| <td>The target package name. If omitted, a default package (formed |
| using the target namespace of the WSDL) will be used. Maps to the |
| -p option of the command line tool.</td> |
| </tr> |
| |
| <tr class="a"> |
| |
| <td>databindingName</td> |
| |
| <td>Data binding framework name. Maps to the -d option of the |
| command line tool. Possible values include "adb", "xmlbeans", |
| "jibx".</td> |
| </tr> |
| |
| <tr class="b"> |
| |
| <td>serviceName</td> |
| |
| <td>The name of the service in the case of multiple services. Maps |
| to -sn options of the command line tool.</td> |
| </tr> |
| |
| <tr class="a"> |
| |
| <td>portName</td> |
| |
| <td>The name of the port in the presence of multiple ports. Maps to |
| -pn options of the command line tool.</td> |
| </tr> |
| |
| <tr class="b"> |
| |
| <td>asyncOnly</td> |
| |
| <td>Generate code only for async style. When this option is used |
| the generated stubs will have only the asynchronous invocation |
| methods. Defaults to false if omitted. Only true and false are |
| applicable as values. Maps to the -a option of the command line |
| tool.</td> |
| </tr> |
| |
| <tr class="a"> |
| |
| <td>syncOnly</td> |
| |
| <td>Generate code only for sync style. When this option is used the |
| generated stubs will have only the synchronous invocation methods. |
| Defaults to false if omitted. Only true and false are applicable as |
| values. Maps to the -s option of the command line tool.</td> |
| </tr> |
| |
| <tr class="b"> |
| |
| <td>serverSide</td> |
| |
| <td>Generates server side code (i.e. skeletons). Only true and |
| false are applicable as values. Default is false. Maps to the -ss |
| option of the command line tool.</td> |
| </tr> |
| |
| <tr class="a"> |
| |
| <td>testcase</td> |
| |
| <td>Generates a test case. Possible values are true and false. Maps |
| to the -t options of the command line tool.</td> |
| </tr> |
| |
| <tr class="b"> |
| |
| <td>generateServiceXml</td> |
| |
| <td>Generates server side code (i.e. skeletons). Only true and |
| false are applicable as values. Default is false. Maps to the -sd |
| option of the command line tool.</td> |
| </tr> |
| |
| <tr class="a"> |
| |
| <td>unpackClasses</td> |
| |
| <td>Unpacks the generated classes. This forces the databinding |
| classes to be generated separately, which otherwise would have been |
| generated as inner classes.</td> |
| </tr> |
| |
| <tr class="b"> |
| |
| <td>generateAllClasses</td> |
| |
| <td>Generates all the classes including client and server side |
| code. Maps to the -g option of the command line tool.</td> |
| </tr> |
| |
| <tr class="a"> |
| |
| <td>namespaceToPackages</td> |
| |
| <td>A list of namespace to package mappings.</td> |
| </tr> |
| |
| <tr class="b"> |
| |
| <td>serverSideInterface</td> |
| |
| <td>Flag stating whether to generate an interface for the server |
| side skeleton.</td> |
| </tr> |
| |
| <tr class="a"> |
| |
| <td>repositoryPath</td> |
| |
| <td>Sets the repository path to be used. Maps to the -r option of |
| the command line tool.</td> |
| </tr> |
| |
| <tr class="b"> |
| |
| <td>wsdlVersion</td> |
| |
| <td>Sets the version of the wsdl that is being used during |
| codegeneration. This deafults to 1.1 and one can set this to 2, |
| when trying to work with a WSDL 2.0 document. Maps to the -wv |
| option of the command line tool.</td> |
| </tr> |
| |
| <tr class="a"> |
| |
| <td>externalMapping</td> |
| |
| <td>Location of the external mapping file to be used. Maps to the |
| -em option of the command line tool.</td> |
| </tr> |
| |
| <tr class="b"> |
| |
| <td>targetSourceFolderLocation</td> |
| |
| <td>Rather than dumping all the code in the same location, one has |
| the option to make the sources to be generated in a different |
| location, given using this option. Maps to the -S option of the |
| command line tool.</td> |
| </tr> |
| |
| <tr class="a"> |
| |
| <td>targetResourcesFolderLocation</td> |
| |
| <td>Rather than dumping all the code in the same location, one has |
| the option to make the resources to be generated in a different |
| location, given using this option. Maps to the -R option of the |
| command line tool.</td> |
| </tr> |
| |
| <tr class="b"> |
| |
| <td>unwrap</td> |
| |
| <td>This will select between wrapped and unwrapped during code |
| generation. Default is set to false. Maps to the -uw option of the |
| command line tool.</td> |
| </tr> |
| </tbody> |
| </table> |
| <a name="example" id="example"></a> |
| </div> |
| <div class="section"> |
| <h3><a name="Example_Build_File_Using_the_Custom_Ant_Task"></a>Example Build File Using the Custom Ant Task</h3> |
| |
| <p>Following is an example ant build file that uses the custom Ant |
| task. You can use any wsdl file to test the example. Replace the |
| "CombinedService.wsdl" with the name of your wsdl file in the |
| following script.</p> |
| |
| <div> |
| <pre> |
| 1 <?xml version="1.0"?> |
| 2 <project name="CodegenExample" default="main" basedir="."> |
| 3 |
| 4 <path id="example.classpath"> |
| 5 <fileset dir="classes"> |
| 6 <include name="**/*.jar" /> |
| 7 </fileset> |
| 8 </path> |
| 9 |
| 10 <target name="declare" > |
| 11 <taskdef name="codegen" |
| 12 classname="org.apache.axis2.tool.ant.AntCodegenTask" |
| 13 classpathref="example.classpath"/> |
| 15 </target> |
| 16 |
| 17 <target name="main" depends="declare"> |
| 18 <codegen |
| 19 wsdlfilename="C:\test\wsdl\CombinedService.wsdl" |
| 20 output="C:\output" |
| 21 serverside="true" |
| 22 generateservicexml="true"/> |
| 23 </target> |
| 24 |
| 25 </project> |
| </pre></div> |
| |
| <p>In the above build script, from line 4 to 8 it sets the |
| classpath and includes all the .jar files (which are listed below) |
| into the classpath. From line 10 to 15 it creates a target to |
| declare a task called "codegen" and sets the appropriate class |
| (org.apache.axis2.tool.ant.AntCodegenTask) within the classpath in |
| line 12. From line 17 to 23 it creates the "main" target to |
| generate the code from the given wsdl. There are some arguments set |
| form line 19 to 22. Here in line 19 it sets the location of the |
| wsdl. In line 20 it sets the output directory in which the code is |
| generated. Line 21 indicates that this build generates the server |
| side code(skeleton) and line 22 indicates that the services.xml is |
| also generated.</p> |
| |
| <p>Notice the main target that uses the "codegen" task which will |
| use the org.apache.axis2.tool.ant.AntCodegenTask class and run the |
| code generation tool internally while passing the relevant |
| arguments and do the proper generation. If a user types</p> |
| |
| <p><tt>>ant</tt> or <tt>>ant main</tt></p> |
| |
| <p>it will generate the server side code and services.xml for the |
| given WSDL file (C:\test\wsdl\CombinedService.wsdl -in the above |
| instance) and the generated code will be written to the specified |
| output path (C:\output - in the above instance).</p> |
| |
| <p>For this Ant task to work the following jars need to be in the |
| class path.</p> |
| |
| <ul> |
| |
| <li>axis2-*.jar (from the Axis2 distribution)</li> |
| |
| <li>wsdl4j-1.6.2.jar or higher (The WSDL4J implementation jar. |
| Bundled with the Axis2 distribution)</li> |
| |
| <li>stax-api-1.0.1.jar (The StAX API's that contain the |
| javax.xml.namespace.QName class. This jar may be replaced by any |
| other jar that contains the javax.xml.namespace.QName |
| implementation. However Axis2 uses this class from the |
| stax-api-1.0.1.jar which comes bundled with the Axis2 |
| distribution)</li> |
| |
| <li>commons-logging-1.1.jar, neethi-2.0.jar and XmlSchema-1.2.jar |
| (from the Axis2 distribution)</li> |
| |
| <li>axiom-api-1.2.1.jar and axiom-impl-1.2.1.jar (from the Axis2 |
| distribution)</li> |
| |
| <li>activation-1.1.jar (from the Axis2 distribution)</li> |
| |
| <li>wstx-asl-3.1.0.jar (from the Axis2 distribution)</li> |
| </ul> |
| <a name="invoking" id="invoking"></a> |
| </div> |
| <div class="section"> |
| <h3><a name="Invoking_the_Code_Generator_From_Ant"></a>Invoking the Code Generator From Ant</h3> |
| |
| <p>Since the users may find altering their ant class path a bit |
| daunting they can also follow an easier technique. The code |
| generator main class can be invoked directly through the build |
| file.</p> |
| |
| <p>Below is an example of a full build.xml needed to run WSDL2Java |
| and generate the Java source files, compile the sources, and build |
| an AAR file ready for deployment (These are done one by one, by |
| calling the targets in the build file separately):</p> |
| |
| <div> |
| <pre class="code"> |
| <!DOCTYPE project> |
| |
| <project name="wsdl2java-example" default="usage" basedir="."> |
| |
| <property name="project-name" value="wsdl2java-example"/> |
| <property file="build.properties"/> |
| |
| <property name="build" value="build"/> |
| <property name="src" value="src"/> |
| <property name="build.classes" value="build/classes" /> |
| |
| <path id="axis.classpath"> |
| <pathelement location="build/classes" /> |
| <fileset dir="${axis.home}/lib"> |
| <include name="**/*.jar" /> |
| </fileset> |
| <pathelement location="${build.classes}" /> |
| </path> |
| |
| <path id="axis_client.classpath"> |
| <pathelement location="build/classes" /> |
| <fileset dir="${axis.home}"> |
| <include name="**/*.jar" /> |
| </fileset> |
| <fileset dir="lib"> |
| <include name="*.jar" /> |
| </fileset> |
| <pathelement location="${build.classes}" /> |
| </path> |
| |
| <target name="usage" description="Build file usage info (default task)"> |
| <echo message=" " /> |
| <echo message="${project-name} " /> |
| <echo message="-------------------------------------------------------" /> |
| <echo message=" " /> |
| <echo message="Available Targets:" /> |
| <echo message=" " /> |
| <echo message=" Compiling:" /> |
| <echo message=" compile - Compiles the WSDL2Java source code" /> |
| <echo message=" " /> |
| <echo message=" Compiling client:" /> |
| <echo message=" compile_client - Compiles the client source code" /> |
| <echo message=" " /> |
| <echo message=" Cleaning up:" /> |
| <echo message=" clean - Delete class files" /> |
| <echo message=" " /> |
| <echo message=" WSDL:" /> |
| <echo message=" wsdl2java - Generate source from WSDL" /> |
| <echo message=" " /> |
| <echo message=" AAR:" /> |
| <echo message=" aar - Generate an .aar for deployment into WEB-INF/services" /> |
| <echo message=" " /> |
| <echo message=" Executing:" /> |
| <echo message=" runLogin - Execute the runLogin client" /> |
| </target> |
| |
| <target name="prepare" > |
| <mkdir dir="${build.classes}" /> |
| </target> |
| |
| <target name="clean" > |
| <delete dir="${build}" /> |
| <delete dir="${dist}" /> |
| </target> |
| |
| <target name="compile"> |
| <echo message="Compiling wsdl2 files"/> |
| |
| <javac |
| srcdir="output" |
| destdir="${build.classes}" |
| deprecation="true" |
| failonerror="true" debug="true"> |
| |
| <classpath refid="axis.classpath"/> |
| </javac> |
| |
| </target> |
| |
| <target name="wsdl2java" depends="clean,prepare"> |
| <delete dir="output" /> |
| <java classname="org.apache.axis2.wsdl.WSDL2Java" fork="true"> |
| <classpath refid="axis.classpath"/> |
| <arg value="-d"/> |
| <arg value="xmlbeans"/> |
| <arg value="-uri"/> |
| <arg file="wsdl/LoginEndpoint.wsdl"/> |
| <arg value="-ss"/> |
| <arg value="-g"/> |
| <arg value="-sd"/> |
| <arg value="-o"/> |
| <arg file="output"/> |
| <arg value="-p"/> |
| <arg value="org.example.types"/> |
| </java> |
| |
| <!-- Move the schema folder to classpath--> |
| <move todir="${build.classes}"> |
| <fileset dir="output/resources"> |
| <include name="**/*schema*/**/*.class"/> |
| <include name="**/*schema*/**/*.xsb"/> |
| </fileset> |
| </move> |
| |
| </target> |
| |
| <target name="jar_wsdl" depends="compile"> |
| <jar jarfile="lib/axis2_example_wsdl.jar" > |
| <fileset dir="${build.classes}" /> |
| </jar> |
| </target> |
| |
| <!-- build an .aar file for axis2 web services --> |
| <target name="aar" depends="compile"> |
| <delete dir="${build.classes}/META-INF" /> |
| <mkdir dir="${build.classes}/META-INF" /> |
| <copy todir="${build.classes}/META-INF" > |
| <fileset dir="output/resources" > |
| <!-- axis2 web services definitions file --> |
| <include name="services.xml"/> |
| </fileset> |
| <fileset dir="wsdl" > |
| <include name="LoginEndpoint.wsdl"/> |
| </fileset> |
| </copy> |
| <jar jarfile="dist/LoginEndpoint.aar" > |
| <fileset dir="${build.classes}" /> |
| </jar> |
| </target> |
| |
| <target name="compile_client"> |
| <echo message="Compiling client files"/> |
| |
| <javac |
| srcdir="src" |
| destdir="${build.classes}" |
| deprecation="true" |
| failonerror="true" debug="true"> |
| |
| <classpath refid="axis.classpath"/> |
| </javac> |
| |
| </target> |
| |
| <target name="runLogin" depends="prepare,compile_client" description="run simple Login client"> |
| <java classname="org.client.LoginClient" > |
| <classpath refid="axis_client.classpath"/> |
| </java> |
| </target> |
| |
| </project> |
| </pre></div> |
| |
| <p>Place the above build.xml file in the 'bin' directory of the |
| axis2 binary distribution. Then create a build.properties file in |
| the same directory and specify the axis.home path pointing to the |
| axis2 binary distribution</p> |
| |
| <p>E.g. :- axis.home=C://Axis2//axis2-1.1-bin</p> |
| |
| <p>The above build.xml example also assumes three empty directories |
| exist, 'dist', 'lib', and 'src'.</p> |
| |
| <p>Below is a validated WSDL Document following the |
| Document/Literal Style. The name of this file matches the name used |
| in the WSDL2Java ant task above, LoginEndpoint.wsdl.</p> |
| |
| <div> |
| <pre class="code"> |
| <?xml version="1.0" encoding="UTF-8"?> |
| |
| <definitions name="LoginService" targetNamespace="http://login" xmlns:tns="http://login" |
| xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" |
| xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns2="http://login/types"> |
| |
| <types> |
| <schema targetNamespace="http://login/types" xmlns:tns="http://login/types" |
| xmlns:soap11-enc="http://schemas.xmlsoap.org/soap/encoding/" |
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" |
| xmlns="http://www.w3.org/2001/XMLSchema"> |
| <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/> |
| <element name="returnWebLoginElement"> |
| <complexType> |
| <sequence> |
| |
| <element ref="tns:soap_session_idElement"/> |
| <element ref="tns:web_user_nameElement"/> |
| </sequence> |
| </complexType> |
| </element> |
| <element name="webLoginElement"> |
| |
| <complexType> |
| <sequence> |
| <element ref="tns:user_nameElement"/> |
| <element ref="tns:user_passwordElement"/> |
| </sequence> |
| </complexType> |
| |
| </element> |
| <element name="user_nameElement" type="xsd:string"/> |
| <element name="user_passwordElement" type="xsd:string"/> |
| <element name="soap_session_idElement" type="xsd:string"/> |
| <element name="web_user_nameElement" type="xsd:string"/> |
| </schema></types> |
| |
| <message name="LoginEndpoint_webLogin"> |
| <part name="parameters" element="ns2:webLoginElement"/> |
| </message> |
| <message name="LoginEndpoint_webLoginResponse"> |
| <part name="result" element="ns2:returnWebLoginElement"/> |
| </message> |
| |
| <portType name="LoginEndpoint"> |
| <operation name="webLogin"> |
| <input message="tns:LoginEndpoint_webLogin" name="LoginEndpoint_webLogin"/> |
| <output message="tns:LoginEndpoint_webLoginResponse" name="LoginEndpoint_webLoginResponse"/> |
| </operation> |
| </portType> |
| |
| <binding name="LoginEndpointBinding" type="tns:LoginEndpoint"> |
| <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/> |
| <operation name="webLogin"> |
| <soap:operation soapAction="webLogin"/> |
| <input name="LoginEndpoint_webLogin"> |
| <soap:body use="literal"/> |
| |
| </input> |
| <output name="LoginEndpoint_webLoginResponse"> |
| <soap:body use="literal"/> |
| </output> |
| </operation> |
| </binding> |
| |
| <service name="LoginService"> |
| <port name="LoginEndpointPort" binding="tns:LoginEndpointBinding"> |
| <soap:address location="http://localhost:8080/axis2/services/LoginService"/></port> |
| </service></definitions> |
| </pre></div> |
| |
| <p>Place the above file, named LoginEndpoint.wsdl, in the directory |
| 'wsdl' which is also inside the 'bin' directory. Run the wsdl2java |
| command via the ant task defined above (>ant wsdl2java), and |
| there will be a directory called 'output' created. This directory |
| contains the WSDL2Java generated source.</p> |
| |
| <p>An important detail is that an XMLBean class file is also |
| generated by WSDL2Java, TypeSystemHolder.class. That file is placed |
| into build/classes by the above ant task and will be needed to |
| compile the generated sources. A frequent problem is users get an |
| error such as:</p> |
| |
| <p><i><b>ClassNotFoundException : Cannot load SchemaTypeSystem. |
| Unable to load class with name |
| schemaorg_apache_xmlbeans.system.s68C41DB812F52C975439BA10FE4FEE54.TypeSystemHolder. |
| Make sure the generated binary files are on the |
| classpath.</b></i></p> |
| |
| <p>The TypeSystemHolder.class generated by WSDL2Java must be placed |
| in your classpath in order to avoid this error.</p> |
| |
| <p>The next step is to modify the generated Skeleton Java Source |
| file - the Web service. This file as generated returns null and |
| needs to be updated to contain the business logic.</p> |
| |
| <p>After the WSDL2Java command runs the file LoginEndpoint.wsdl, |
| edit the following file:</p> |
| |
| <p>output/src/org/example/types/LoginServiceSkeleton.java. You |
| should see the following code:</p> |
| |
| <div> |
| <pre class="code"> |
| /** |
| * LoginServiceSkeleton.java |
| * |
| * This file was auto-generated from WSDL |
| * by the Apache Axis2 version: 1.0-RC4 Apr 28, 2006 (05:23:23 IST) |
| */ |
| package org.example.types; |
| /** |
| * LoginServiceSkeleton java skeleton for the axisService |
| */ |
| public class LoginServiceSkeleton { |
| |
| |
| /** |
| * Auto generated method signature |
| |
| * @param param0 |
| |
| */ |
| public login.types.ReturnWebLoginElementDocument webLogin |
| (login.types.WebLoginElementDocument param0 ) |
| |
| { |
| //Todo fill this with the necessary business logic |
| throw new java.lang.UnsupportedOperationException(); |
| } |
| |
| } |
| </pre></div> |
| |
| <p>Replace the contents of this file with the following, which uses |
| the complex types generated by WSDL2Java and the example wsdl |
| file:</p> |
| |
| <div> |
| <pre class="code"> |
| /** |
| * LoginServiceSkeleton.java |
| * |
| * This file was auto-generated from WSDL |
| * by the Apache Axis2 version: 1.0-RC4 Apr 28, 2006 (05:23:23 IST) |
| */ |
| package org.example.types; |
| import login.types.ReturnWebLoginElementDocument; |
| import login.types.ReturnWebLoginElementDocument.*; |
| import login.types.WebLoginElementDocument; |
| import login.types.WebLoginElementDocument.*; |
| |
| /** |
| * Auto generated java skeleton for the service by the Axis code generator |
| */ |
| public class LoginServiceSkeleton { |
| |
| /** |
| * Auto generated method signature |
| |
| * @param webLoginElementDocument changed from param0 |
| |
| */ |
| public ReturnWebLoginElementDocument webLogin |
| (WebLoginElementDocument webLoginElementDocument ){ |
| |
| //Todo fill this with the necessary business logic |
| System.out.println("LoginServiceSkeleton.webLogin reached successfully!"); |
| |
| // Get parameters passed in |
| WebLoginElement webLoginElement = webLoginElementDocument.getWebLoginElement(); |
| String userName = webLoginElement.getUserNameElement(); |
| String password = webLoginElement.getUserPasswordElement(); |
| System.out.println("LoginServiceSkeleton.webLogin userName: " + userName); |
| System.out.println("LoginServiceSkeleton.webLogin password: " + password); |
| |
| // input paramaters would be used here |
| |
| // prepare output |
| ReturnWebLoginElementDocument retDoc = |
| ReturnWebLoginElementDocument.Factory.newInstance(); |
| |
| ReturnWebLoginElement retElement = ReturnWebLoginElement.Factory.newInstance(); |
| |
| retElement.setWebUserNameElement("joe sixpack"); |
| retElement.setSoapSessionIdElement("some_random_string"); |
| System.out.println("validate retElement: " + retElement.validate()); |
| |
| retDoc.setReturnWebLoginElement(retElement); |
| System.out.println("validate retDoc: " + retDoc.validate()); |
| |
| System.out.println("LoginServiceSkeleton.webLogin returning..."); |
| |
| return retDoc; |
| |
| } |
| } |
| </pre></div> |
| |
| <p>The next steps assume the axis2.war has been deployed and has |
| expanded in a servlet container.</p> |
| |
| <p>Run the 'jar_wsdl' ant task from the example build.xml (>ant |
| jar_wsdl), which generates a jar file axis2_example_wsdl.jar in the |
| 'bin/lib' directory. This jar will be used to compile the client, |
| and also will be placed in the servlet container.</p> |
| |
| <p>Next, run the 'aar' ant task from the example build.xml (>ant |
| aar), which generates the deployable axis2 Web service. Place |
| dist/LoginEndpoint.aar into axis2/WEB-INF/services . Place |
| lib/axis2_example_wsdl.jar into axis2/WEB-INF/lib . Verify the |
| happy axis page loaded the services correctly - there should be the |
| service 'LoginEndpoint' with the available operation 'webLogin' |
| displayed.</p> |
| |
| <p>The last step is to create and run the client. In the src |
| directory create the file org.client.LoginClient.java, with the |
| contents below:</p> |
| |
| <div> |
| <pre class="code"> |
| package org.client; |
| |
| import org.apache.axis2.AxisFault; |
| |
| import login.types.ReturnWebLoginElementDocument; |
| import login.types.ReturnWebLoginElementDocument.*; |
| import login.types.WebLoginElementDocument; |
| import login.types.WebLoginElementDocument.*; |
| import org.example.types.LoginServiceStub; |
| |
| /** |
| * Login. |
| * |
| */ |
| public class LoginClient { |
| |
| public static void main(String[] args) { |
| try { |
| |
| System.out.println("webLogin, firing..."); |
| LoginServiceStub stub = new LoginServiceStub(); |
| |
| WebLoginElementDocument webLoginElementDocument |
| = WebLoginElementDocument.Factory.newInstance(); |
| WebLoginElement webLoginElement = |
| WebLoginElement.Factory.newInstance(); |
| webLoginElement.setUserNameElement("joe"); |
| webLoginElement.setUserPasswordElement("sixpack"); |
| |
| webLoginElementDocument.setWebLoginElement(webLoginElement); |
| |
| System.out.println("validate: " + webLoginElement.validate()); |
| stub.webLogin(webLoginElementDocument); |
| |
| ReturnWebLoginElementDocument returnWebLoginElementDocument = |
| stub.webLogin(webLoginElementDocument); |
| |
| System.out.println("Client returned"); |
| |
| ReturnWebLoginElementDocument.ReturnWebLoginElement |
| retElement = returnWebLoginElementDocument.getReturnWebLoginElement(); |
| |
| System.out.println("WebUserName: " + retElement.getWebUserNameElement()); |
| System.out.println("SOAPSessionId: " + retElement.getSoapSessionIdElement()); |
| System.out.println("webLogin, completed!!!"); |
| |
| } catch (AxisFault axisFault) { |
| axisFault.printStackTrace(); |
| } catch (Exception ex) { |
| ex.printStackTrace(); |
| } |
| } |
| } |
| </pre></div> |
| |
| <p>Now run the ant task 'runLogin' (>ant runLogin). The |
| following output should appear:</p> |
| |
| <div> |
| <pre class="code"> |
| runLogin: |
| [echo] running the webLogin client |
| [java] webLogin, firing... |
| [java] validate: true |
| [java] Client returned |
| [java] WebUserName: joe sixpack |
| [java] SOAPSessionId: some_random_string |
| [java] webLogin, completed!!! |
| </pre></div> |
| <a name="appendix" id="appendix"></a> |
| </div> |
| <div class="section"> |
| <h2><a name="Appendix"></a>Appendix</h2> |
| |
| <ul> |
| |
| <li>Eclipse reference - <a class="externalLink" href="http://www.eclipse.org/">http://www.eclipse.org/</a></li> |
| |
| <li>Custom Ant Tasks - <a class="externalLink" href="http://ant.apache.org/manual/develop.html">http://ant.apache.org/manual/develop.html</a></li> |
| </ul> |
| |
| </html> |
| </div> |
| </div> |
| </div> |
| <hr/> |
| <footer> |
| <div class="container-fluid"> |
| <div class="row-fluid"> |
| <p>Copyright ©2004–2017 |
| <a href="https://www.apache.org/">The Apache Software Foundation</a>. |
| All rights reserved.</p> |
| </div> |
| </div> |
| </footer> |
| </body> |
| </html> |