cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache CXF Documentation > Maven cxf-codegen-plugin (WSDL to Java)
Date Thu, 03 Sep 2009 20:35:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CXF20DOC&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="http://cwiki.apache.org/confluence/display/CXF20DOC/Maven+cxf-codegen-plugin+%28WSDL+to+Java%29">Maven
cxf-codegen-plugin (WSDL to Java)</a></h2>
    <h4>Page  <b>added</b> by             <a href="http://cwiki.apache.org/confluence/display/~christian%2Bschneider">Christian
Schneider</a>
    </h4>
         <br/>
    <div class="notificationGreySide">
         <p>CXF includes a Maven plugin which can generate java artifacts from WSDL.
Here is a simple example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;plugin&gt;</span>
	<span class="code-tag">&lt;groupId&gt;</span>org.apache.cxf<span class="code-tag">&lt;/groupId&gt;</span>
	<span class="code-tag">&lt;artifactId&gt;</span>cxf-codegen-plugin<span
class="code-tag">&lt;/artifactId&gt;</span>
	<span class="code-tag">&lt;version&gt;</span>${cxf.version}<span class="code-tag">&lt;/version&gt;</span>
	<span class="code-tag">&lt;executions&gt;</span>
		<span class="code-tag">&lt;execution&gt;</span>
			<span class="code-tag">&lt;id&gt;</span>generate-sources<span class="code-tag">&lt;/id&gt;</span>
			<span class="code-tag">&lt;phase&gt;</span>generate-sources<span
class="code-tag">&lt;/phase&gt;</span>
			<span class="code-tag">&lt;configuration&gt;</span>
				<span class="code-tag">&lt;sourceRoot&gt;</span>${project.build.directory}/generated/cxf<span
class="code-tag">&lt;/sourceRoot&gt;</span>                             
  
				<span class="code-tag">&lt;wsdlOptions&gt;</span>
					<span class="code-tag">&lt;wsdlOption&gt;</span>
						<span class="code-tag">&lt;wsdl&gt;</span>${basedir}/src/main/wsdl/myService.wsdl<span
class="code-tag">&lt;/wsdl&gt;</span>
					<span class="code-tag">&lt;/wsdlOption&gt;</span>
				<span class="code-tag">&lt;/wsdlOptions&gt;</span>
			<span class="code-tag">&lt;/configuration&gt;</span>
			<span class="code-tag">&lt;goals&gt;</span>
				<span class="code-tag">&lt;goal&gt;</span>wsdl2java<span class="code-tag">&lt;/goal&gt;</span>
			<span class="code-tag">&lt;/goals&gt;</span>
		<span class="code-tag">&lt;/execution&gt;</span>
	<span class="code-tag">&lt;/executions&gt;</span>
<span class="code-tag">&lt;/plugin&gt;</span>
</pre>
</div></div>
<p>In this example we're running the wsdl2java goal in the generate-sources phase. By
running <b>mvn generate-sources</b>, CXF will generate artifacts in the &lt;sourceRoot&gt;
directory that you specify. Each &lt;wsdlOption&gt; element corresponds to a WSDL
that you're generated artifacts for. In the above example we're generating we're specifying
the WSDL location via the &lt;wsdl&gt; option.</p>

<p>Other configuration arguments can be include inside the &lt;wsdlOption&gt;
element. These pass arguments to the tooling and correspond to the options outlined on the
<a href="/confluence/display/CXF20DOC/WSDL+to+Java" title="WSDL to Java">WSDL to Java</a>
page.</p>

<p>For CXF 2.1.4 and latter you don't need anymore to specify the &lt;phase&gt;,
as generate-sources is the default.<br/>
For CXF 2.2 and latter you don't even need to specify the &lt;sourceRoot&gt; to match
maven convention for using target/generated-sources/cxf as output folder for generated classes.</p>

<h3><a name="Mavencxf-codegen-plugin%28WSDLtoJava%29-Example1%3APassinginaJAXWSBindingfile"></a>Example
1: Passing in a JAX-WS Binding file</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;configuration&gt;</span>
  <span class="code-tag">&lt;sourceRoot&gt;</span>${basedir}/target/generated/cxf<span
class="code-tag">&lt;/sourceRoot&gt;</span>
  <span class="code-tag">&lt;wsdlOptions&gt;</span>
    <span class="code-tag">&lt;wsdlOption&gt;</span>
      <span class="code-tag">&lt;wsdl&gt;</span>${basedir}/src/main/wsdl/myService.wsdl<span
class="code-tag">&lt;/wsdl&gt;</span>
      <span class="code-tag">&lt;bindingFiles&gt;</span>
        <span class="code-tag">&lt;bindingFile&gt;</span>${basedir}/src/main/resources/wsdl/async_binding.xml<span
class="code-tag">&lt;/bindingFile&gt;</span>
      <span class="code-tag">&lt;/bindingFiles&gt;</span>
    <span class="code-tag">&lt;/wsdlOption&gt;</span>
  <span class="code-tag">&lt;/wsdlOptions&gt;</span>
<span class="code-tag">&lt;/configuration&gt;</span>
</pre>
</div></div>
<p>In this example we're specifying that we want CXF to use our JAX-WS binding file.
Binding files are a way to customize the output of the artifacts that CXF generates. For instance,
it allows you to change the package name CXF uses.</p>

<h3><a name="Mavencxf-codegen-plugin%28WSDLtoJava%29-Example2%3ASpecifyingaservicetogenerateartifactsfor"></a>Example
2: Specifying a service to generate artifacts for</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;configuration&gt;</span>
  <span class="code-tag">&lt;sourceRoot&gt;</span>${basedir}/target/generated/src/main/java<span
class="code-tag">&lt;/sourceRoot&gt;</span>
  <span class="code-tag">&lt;wsdlOptions&gt;</span>
    <span class="code-tag">&lt;wsdlOption&gt;</span>
      <span class="code-tag">&lt;wsdl&gt;</span>${basedir}/src/main/wsdl/myService.wsdl<span
class="code-tag">&lt;/wsdl&gt;</span>
      <span class="code-tag">&lt;serviceName&gt;</span>MyWSDLService<span
class="code-tag">&lt;/serviceName&gt;</span>
    <span class="code-tag">&lt;/wsdlOption&gt;</span>
  <span class="code-tag">&lt;/wsdlOptions&gt;</span>
<span class="code-tag">&lt;/configuration&gt;</span>
</pre>
</div></div>
<p>In this example we're specifying that we only want to generate artifacts for the
service named "MyWSDLService" in the WSDL.</p>

<p>To avoid copy/paste in multiple &lt;wsdlOption&gt; you can also declare a
&lt;defaultOption&gt; element.</p>

<h3><a name="Mavencxf-codegen-plugin%28WSDLtoJava%29-Example3%3AUsingdefaultOptiontoavoidrepetition"></a>Example
3: Using defaultOption to avoid repetition</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;configuration&gt;</span>
  <span class="code-tag">&lt;sourceRoot&gt;</span>${basedir}/target/generated/cxf<span
class="code-tag">&lt;/sourceRoot&gt;</span>
  <span class="code-tag">&lt;defaultOptions&gt;</span>
      <span class="code-tag">&lt;bindingFiles&gt;</span>
          <span class="code-tag">&lt;bindingFile&gt;</span>${basedir}/src/main/jaxb/bindings.xml<span
class="code-tag">&lt;/bindingFile&gt;</span>
      <span class="code-tag">&lt;/bindingFiles&gt;</span>
      <span class="code-tag">&lt;noAddressBinding&gt;</span>true<span
class="code-tag">&lt;/noAddressBinding&gt;</span>
  <span class="code-tag">&lt;/defaultOptions&gt;</span>
  <span class="code-tag">&lt;wsdlOptions&gt;</span>
      <span class="code-tag">&lt;wsdlOption&gt;</span>
          <span class="code-tag">&lt;wsdl&gt;</span>${basedir}/src/main/wsdl/myService.wsdl<span
class="code-tag">&lt;/wsdl&gt;</span>
          <span class="code-tag">&lt;serviceName&gt;</span>MyWSDLService<span
class="code-tag">&lt;/serviceName&gt;</span>
      <span class="code-tag">&lt;/wsdlOption&gt;</span>
      <span class="code-tag">&lt;wsdlOption&gt;</span>
          <span class="code-tag">&lt;wsdl&gt;</span>${basedir}/src/main/wsdl/myOtherService.wsdl<span
class="code-tag">&lt;/wsdl&gt;</span>
          <span class="code-tag">&lt;serviceName&gt;</span>MyOtherWSDLService<span
class="code-tag">&lt;/serviceName&gt;</span>
      <span class="code-tag">&lt;/wsdlOption&gt;</span>
  <span class="code-tag">&lt;/wsdlOptions&gt;</span>
<span class="code-tag">&lt;/configuration&gt;</span>
</pre>
</div></div>

<p>&lt;defaultOption&gt; and &lt;wsdlOption&gt; correspond to the options
outlined on the <a href="/confluence/display/CXF20DOC/WSDL+to+Java" title="WSDL to Java">WSDL
to Java</a> page, you may look at <a href="http://svn.apache.org/repos/asf/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/Option.java"
rel="nofollow">http://svn.apache.org/repos/asf/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/Option.java</a>
for a more detailed description of those parameters.</p>

<p>At least, you can declare a common wsdlRoot folder where you store your WSDL files
and use includes/excludes patterns to select the files to get used by the code generator</p>

<h3><a name="Mavencxf-codegen-plugin%28WSDLtoJava%29-Example4%3AUsingwsdlRootwithincludes%2Fexcludespatterns"></a>Example
4: Using wsdlRoot with includes/excludes patterns</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;configuration&gt;</span>
  <span class="code-tag">&lt;sourceRoot&gt;</span>${basedir}/target/generated/cxf<span
class="code-tag">&lt;/sourceRoot&gt;</span>
  <span class="code-tag">&lt;defaultOptions&gt;</span>
      <span class="code-tag">&lt;bindingFiles&gt;</span>
          <span class="code-tag">&lt;bindingFile&gt;</span>${basedir}/src/main/jaxb/bindings.xml<span
class="code-tag">&lt;/bindingFile&gt;</span>
      <span class="code-tag">&lt;/bindingFiles&gt;</span>
      <span class="code-tag">&lt;noAddressBinding&gt;</span>true<span
class="code-tag">&lt;/noAddressBinding&gt;</span>
  <span class="code-tag">&lt;/defaultOptions&gt;</span>
  <span class="code-tag">&lt;wsdlRoot&gt;</span>${basedir}/src/main/resources/wsdl<span
class="code-tag">&lt;/wsdlRoot&gt;</span>
  <span class="code-tag">&lt;includes&gt;</span>
      <span class="code-tag">&lt;include&gt;</span>*Service.wsdl<span
class="code-tag">&lt;/include&gt;</span>
  <span class="code-tag">&lt;/includes&gt;</span>
<span class="code-tag">&lt;/configuration&gt;</span>
</pre>
</div></div>

<p>wsdlRoot default value is <tt>src/main/resources/wsdl</tt> so you may
omit this declaration.</p>
    </div>
    <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>
       <a href="http://cwiki.apache.org/confluence/display/CXF20DOC/Maven+cxf-codegen-plugin+%28WSDL+to+Java%29">View
Online</a>
              |
       <a href="http://cwiki.apache.org/confluence/display/CXF20DOC/Maven+cxf-codegen-plugin+%28WSDL+to+Java%29?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
           </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message