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 Mon, 30 Jul 2012 19:31:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=CXF20DOC&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://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>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~mazzag">Glen
Mazza</a>
    </h4>
        <div id="versionComment">
        <b>Comment:</b>
        Better standardized a bit folder locations for the WSDL file.<br />
    </div>
        <br/>
                         <h4>Changes (9)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >				&lt;wsdlOptions&gt; <br>
				&lt;wsdlOption&gt; <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">&lt;wsdl&gt;${basedir}/src/main/wsdl/myService.wsdl&lt;/wsdl&gt;</span>
<span class="diff-added-words"style="background-color: #dfd;">&lt;wsdl&gt;${basedir}/src/main/resources/myService.wsdl&lt;/wsdl&gt;</span>
<br></td></tr>
            <tr><td class="diff-unchanged" >					&lt;/wsdlOption&gt; <br>
			&lt;/wsdlOptions&gt; <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >&lt;/plugin&gt; <br>{code}
<br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">In
this example we&#39;re running the wsdl2java goal in the generate-sources phase. By running
*mvn generate-sources*, CXF will generate artifacts in the &lt;sourceRoot&gt; directory
that you specify. Each &lt;wsdlOption&gt; element corresponds to a WSDL that you&#39;re
generated artifacts for. In the above example we&#39;re generating we&#39;re specifying
the WSDL location via the &lt;wsdl&gt; option. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">In
this example we&#39;re running the wsdl2java goal in the generate-sources phase. By running
*mvn generate-sources*, CXF will generate artifacts in the &lt;sourceRoot&gt; directory
that you specify. Each &lt;wsdlOption&gt; element corresponds to a WSDL that you&#39;re
generated artifacts for. The WSDL location is specified via the &lt;wsdl&gt; option.
 Following [Maven standard directory layout|http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html],
if you&#39;re planning on packaging the WSDL in the JAR you&#39;re creating you&#39;ll
want the WSDL above in /src/main/resources/  (alternatively in a subfolder underneath it if
desired to avoid placing resources in the root of a JAR); else use the /src/main/config folder
to keep the WSDL out of the JAR. <br></td></tr>
            <tr><td class="diff-unchanged" > <br>The following example shows
some customization options.  By default, the codegen plugin follows the Maven convention of
&quot;target/generated-sources/cxf&quot; for the output folder for the generated classes.
 You can override this value using &lt;sourceRoot&gt; as shown below, but note this
is usually not necessary, the default is fine for most people and can make it easier for some
IDE&#39;s to detect the generated source code.  Other configuration arguments can be included
inside the &lt;wsdlOption&gt; element. These pass arguments to the tooling and correspond
to the options outlined on the [WSDL To Java] page. <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >    &lt;wsdlOptions&gt; <br>
&lt;wsdlOption&gt; <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">&lt;wsdl&gt;${basedir}/src/main/<span
class="diff-added-chars"style="background-color: #dfd;">resources/</span>wsdl/myService.wsdl&lt;/wsdl&gt;</span>
<br></td></tr>
            <tr><td class="diff-unchanged" >                &lt;extraargs&gt;
<br>                    &lt;extraarg&gt;-impl&lt;/extraarg&gt; <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >      &lt;wsdl&gt;${basedir}/src/main/wsdl/myService.wsdl&lt;/wsdl&gt;
<br>      &lt;bindingFiles&gt; <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">&lt;bindingFile&gt;${basedir}/src/main/resources/<span
class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">wsdl/</span>async_binding.xml&lt;/bindingFile&gt;</span>
<br></td></tr>
            <tr><td class="diff-unchanged" >      &lt;/bindingFiles&gt;
<br>    &lt;/wsdlOption&gt; <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >  &lt;wsdlOptions&gt; <br>
   &lt;wsdlOption&gt; <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">&lt;wsdl&gt;${basedir}/src/main/<span
class="diff-added-chars"style="background-color: #dfd;">resources/</span>wsdl/myService.wsdl&lt;/wsdl&gt;</span>
<br></td></tr>
            <tr><td class="diff-unchanged" >      &lt;serviceName&gt;MyWSDLService&lt;/serviceName&gt;
<br>    &lt;/wsdlOption&gt; <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >  &lt;wsdlOptions&gt; <br>
     &lt;wsdlOption&gt; <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">&lt;wsdl&gt;${basedir}/src/main/<span
class="diff-added-chars"style="background-color: #dfd;">resources/</span>wsdl/myService.wsdl&lt;/wsdl&gt;</span>
<br></td></tr>
            <tr><td class="diff-unchanged" >          &lt;serviceName&gt;MyWSDLService&lt;/serviceName&gt;
<br>      &lt;/wsdlOption&gt; <br>      &lt;wsdlOption&gt; <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">&lt;wsdl&gt;${basedir}/src/main/<span
class="diff-added-chars"style="background-color: #dfd;">resources/</span>wsdl/myOtherService.wsdl&lt;/wsdl&gt;</span>
<br></td></tr>
            <tr><td class="diff-unchanged" >          &lt;serviceName&gt;MyOtherWSDLService&lt;/serviceName&gt;
<br>      &lt;/wsdlOption&gt; <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >      &lt;wsdlOptions&gt;
<br>        &lt;wsdlOption&gt; <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">&lt;wsdl&gt;${basedir}/src/main/<span
class="diff-added-chars"style="background-color: #dfd;">resources/</span>wsdl/myService.wsdl&lt;/wsdl&gt;</span>
<br></td></tr>
            <tr><td class="diff-unchanged" >          &lt;extraargs&gt;
<br>            &lt;extraarg&gt;-xjc-b,binding.xjb&lt;/extraarg&gt;
<br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <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/resources/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. The WSDL location is specified via the &lt;wsdl&gt;
option.  Following <a href="http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html"
class="external-link" rel="nofollow">Maven standard directory layout</a>, if you're
planning on packaging the WSDL in the JAR you're creating you'll want the WSDL above in /src/main/resources/
 (alternatively in a subfolder underneath it if desired to avoid placing resources in the
root of a JAR); else use the /src/main/config folder to keep the WSDL out of the JAR.</p>

<p>The following example shows some customization options.  By default, the codegen
plugin follows the Maven convention of "target/generated-sources/cxf" for the output folder
for the generated classes.  You can override this value using &lt;sourceRoot&gt; as
shown below, but note this is usually not necessary, the default is fine for most people and
can make it easier for some IDE's to detect the generated source code.  Other configuration
arguments can be included 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>

<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>${project.build.directory}/generated-code/mywebservice<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/resources/wsdl/myService.wsdl<span
class="code-tag">&lt;/wsdl&gt;</span>
                <span class="code-tag">&lt;extraargs&gt;</span>
                    <span class="code-tag">&lt;extraarg&gt;</span>-impl<span
class="code-tag">&lt;/extraarg&gt;</span>
                    <span class="code-tag">&lt;extraarg&gt;</span>-verbose<span
class="code-tag">&lt;/extraarg&gt;</span>
                <span class="code-tag">&lt;/extraargs&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>See <a href="http://www.jroller.com/gmazza/entry/web_service_tutorial" class="external-link"
rel="nofollow">this blog entry</a> for a full service and client example that uses
the cxf-codegen-plugin.</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;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/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;wsdlOptions&gt;</span>
    <span class="code-tag">&lt;wsdlOption&gt;</span>
      <span class="code-tag">&lt;wsdl&gt;</span>${basedir}/src/main/resources/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;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/resources/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/resources/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"
class="external-link" 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;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>

<h3><a name="Mavencxf-codegen-plugin%28WSDLtoJava%29-Example5%3ALoadingawsdlfromthemavenrepository"></a>Example
5: Loading a wsdl from the maven repository</h3>

<p>For CXF 2.3 and latter there is a new config element &lt;wsdlArtifact&gt;
which can be used to load a wsdl file from the maven repository.</p>

<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;wsdlOptions&gt;</span>
      <span class="code-tag">&lt;wsdlOption&gt;</span>
       <span class="code-tag">&lt;wsdlArtifact&gt;</span>
        <span class="code-tag">&lt;groupId&gt;</span>org.apache.pizza<span
class="code-tag">&lt;/groupId&gt;</span>
	<span class="code-tag">&lt;artifactId&gt;</span>PizzaService<span
class="code-tag">&lt;/artifactId&gt;</span>
	<span class="code-tag">&lt;version&gt;</span>1.0.0<span class="code-tag">&lt;/version&gt;</span>
       <span class="code-tag">&lt;/wsdlArtifact&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>This will load the wsdl /org/apache/pizza/PizzaService-1.0.0.wsdl into your local
maven repository and generate java code from it.</p>

<h3><a name="Mavencxf-codegen-plugin%28WSDLtoJava%29-Example6%3AUsingxjcextensions"></a>Example
6: Using xjc extensions</h3>

<p>Standard JAXB command-line customizations can be added via &lt;extraarg&gt;
elements, either one per line or comma separated.  CXF also offers some JAXB extensions for
the code generation. They have to be added as dependencies and then activated by using an
extraarg with content -xjc-X&lt;extension id&gt; </p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> artifact id </th>
<th class='confluenceTh'> description </th>
<th class='confluenceTh'> extension id </th>
</tr>
<tr>
<td class='confluenceTd'> cxf-xjc-boolean </td>
<td class='confluenceTd'> Adds getters for booleans </td>
<td class='confluenceTd'> boolean </td>
</tr>
<tr>
<td class='confluenceTd'> cxf-xjc-bug671 </td>
<td class='confluenceTd'> Workaroung for JAXB bug 671 </td>
<td class='confluenceTd'> bug671 </td>
</tr>
<tr>
<td class='confluenceTd'> cxf-xjc-dv </td>
<td class='confluenceTd'> Default value support </td>
<td class='confluenceTd'> dv </td>
</tr>
<tr>
<td class='confluenceTd'> cxf-xjc-ts </td>
<td class='confluenceTd'> Adds toString to objects </td>
<td class='confluenceTd'> ts </td>
</tr>
<tr>
<td class='confluenceTd'> cxf-xjc-wsdlextension </td>
<td class='confluenceTd'> WsdlExtension support </td>
<td class='confluenceTd'> wsdlextension </td>
</tr>
<tr>
<td class='confluenceTd'> jaxb-fluent-api </td>
<th class='confluenceTh'> Fluent API for setters </th>
<td class='confluenceTd'>  fluent-api </td>
</tr>
</tbody></table>
</div>


<p>An example showing attachment of a JAXB binding file and the CXF toString() extension
is below:</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;wsdlOptions&gt;</span>
        <span class="code-tag">&lt;wsdlOption&gt;</span>
          <span class="code-tag">&lt;wsdl&gt;</span>${basedir}/src/main/resources/wsdl/myService.wsdl<span
class="code-tag">&lt;/wsdl&gt;</span>
          <span class="code-tag">&lt;extraargs&gt;</span>
            <span class="code-tag">&lt;extraarg&gt;</span>-xjc-b,binding.xjb<span
class="code-tag">&lt;/extraarg&gt;</span>
            <span class="code-tag">&lt;extraarg&gt;</span>-xjc-Xts<span
class="code-tag">&lt;/extraarg&gt;</span>
          <span class="code-tag">&lt;/extraargs&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;dependencies&gt;</span>
    <span class="code-tag">&lt;dependency&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-xjc-ts<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;/dependency&gt;</span>
<span class="code-tag">&lt;/dependencies&gt;</span>
<span class="code-tag">&lt;/plugin&gt;</span>
</pre>
</div></div>


<h3><a name="Mavencxf-codegen-plugin%28WSDLtoJava%29-Example7UsingJAXB%2FJAXWS2.2withJava6"></a>Example
7 - Using JAXB/JAX-WS 2.2 with Java 6</h3>

<p>Java 6 includes JAXB/JAX-WS 2.1 API's and a 2.1 implementations.  However, sometimes
it's desirable to use JAXB or JAX-WS 2.2 instead to obtain various bug fixes and enhancements.
  Using 2.2 with Java 6 and Maven can be a bit tricky as it requires endorsing the API jars
which requires configuration of a bunch of plugins, requires use of "forking", etc...   First
off, both Surefire and the Compiler plugins need to be setup to point at an endorsed dir:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">

<span class="code-tag">&lt;pluginManagement&gt;</span>
    <span class="code-tag">&lt;plugins&gt;</span>
        <span class="code-tag">&lt;plugin&gt;</span>
            <span class="code-tag">&lt;groupId&gt;</span>org.apache.maven.plugins<span
class="code-tag">&lt;/groupId&gt;</span>
            <span class="code-tag">&lt;artifactId&gt;</span>maven-compiler-plugin<span
class="code-tag">&lt;/artifactId&gt;</span>
            <span class="code-tag">&lt;configuration&gt;</span>
                <span class="code-tag">&lt;compilerArguments&gt;</span>
                   <span class="code-tag">&lt;endorseddirs&gt;</span>${project.build.directory}/endorsed<span
class="code-tag">&lt;/endorseddirs&gt;</span>
                <span class="code-tag">&lt;/compilerArguments&gt;</span>
            <span class="code-tag">&lt;/configuration&gt;</span>
        <span class="code-tag">&lt;/plugin&gt;</span>
        <span class="code-tag">&lt;plugin&gt;</span>
            <span class="code-tag">&lt;groupId&gt;</span>org.apache.maven.plugins<span
class="code-tag">&lt;/groupId&gt;</span>
            <span class="code-tag">&lt;artifactId&gt;</span>maven-surefire-plugin<span
class="code-tag">&lt;/artifactId&gt;</span>
            <span class="code-tag">&lt;configuration&gt;</span>
                <span class="code-tag">&lt;forkMode&gt;</span>once<span
class="code-tag">&lt;/forkMode&gt;</span>
                <span class="code-tag">&lt;argLine&gt;</span>-Djava.endorsed.dirs=${project.build.directory}/endorsed<span
class="code-tag">&lt;/argLine&gt;</span>
            <span class="code-tag">&lt;/configuration&gt;</span>
         <span class="code-tag">&lt;/plugin&gt;</span>
    <span class="code-tag">&lt;/plugins&gt;</span>
<span class="code-tag">&lt;/pluginManagement&gt;</span>

You will then need to use the maven-dependency-plugin to copy the needed artifacts into the
endorsed.dir:

{code:xml}
<span class="code-tag">&lt;plugins&gt;</span>
    <span class="code-tag">&lt;plugin&gt;</span>
       <span class="code-tag">&lt;groupId&gt;</span>org.apache.maven.plugins<span
class="code-tag">&lt;/groupId&gt;</span>
       <span class="code-tag">&lt;artifactId&gt;</span>maven-dependency-plugin<span
class="code-tag">&lt;/artifactId&gt;</span>
       <span class="code-tag">&lt;executions&gt;</span>
          <span class="code-tag">&lt;execution&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;goals&gt;</span>
                 <span class="code-tag">&lt;goal&gt;</span>copy<span
class="code-tag">&lt;/goal&gt;</span>
             <span class="code-tag">&lt;/goals&gt;</span>
             <span class="code-tag">&lt;configuration&gt;</span>
                 <span class="code-tag">&lt;artifactItems&gt;</span>
                    <span class="code-tag">&lt;artifactItem&gt;</span>
                       <span class="code-tag">&lt;groupId&gt;</span>javax.xml.bind<span
class="code-tag">&lt;/groupId&gt;</span>
                       <span class="code-tag">&lt;artifactId&gt;</span>jaxb-api<span
class="code-tag">&lt;/artifactId&gt;</span>
                       <span class="code-tag">&lt;version&gt;</span>2.2<span
class="code-tag">&lt;/version&gt;</span>
                    <span class="code-tag">&lt;/artifactItem&gt;</span>
                    <span class="code-tag">&lt;artifactItem&gt;</span>
                       <span class="code-tag">&lt;groupId&gt;</span>javax.xml.ws<span
class="code-tag">&lt;/groupId&gt;</span>
                       <span class="code-tag">&lt;artifactId&gt;</span>jaxws-api<span
class="code-tag">&lt;/artifactId&gt;</span>
                       <span class="code-tag">&lt;version&gt;</span>2.2<span
class="code-tag">&lt;/version&gt;</span>
                    <span class="code-tag">&lt;/artifactItem&gt;</span>
                  <span class="code-tag">&lt;/artifactItems&gt;</span>
                  <span class="code-tag">&lt;outputDirectory&gt;</span>${project.build.directory}/endorsed<span
class="code-tag">&lt;/outputDirectory&gt;</span>
              <span class="code-tag">&lt;/configuration&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>
<span class="code-tag">&lt;/plugins&gt;</span>

</pre>
</div></div>

<p>Finally, you need to do similar setup for the CXF Codegen plugin so it picks up the
2.2 API's and runtimes:</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;configuration&gt;</span>
        <span class="code-tag">&lt;fork&gt;</span>once<span class="code-tag">&lt;/fork&gt;</span>
        <span class="code-tag">&lt;additionalJvmArgs&gt;</span>-Djava.endorsed.dirs=${project.build.directory}/endorsed<span
class="code-tag">&lt;/additionalJvmArgs&gt;</span>
        <span class="code-tag"><span class="code-comment">&lt;!-- rest of
the normal codegen configuration options --&gt;</span></span>
    <span class="code-tag">&lt;/configuraion&gt;</span>
    <span class="code-tag">&lt;dependencies&gt;</span>
        <span class="code-tag">&lt;dependency&gt;</span>
           <span class="code-tag">&lt;groupId&gt;</span>com.sun.xml.bind<span
class="code-tag">&lt;/groupId&gt;</span>
           <span class="code-tag">&lt;artifactId&gt;</span>jaxb-impl<span
class="code-tag">&lt;/artifactId&gt;</span>
           <span class="code-tag">&lt;version&gt;</span>2.2<span class="code-tag">&lt;/version&gt;</span>
        <span class="code-tag">&lt;/dependency&gt;</span>
        <span class="code-tag">&lt;dependency&gt;</span>
           <span class="code-tag">&lt;groupId&gt;</span>com.sun.xml.bind<span
class="code-tag">&lt;/groupId&gt;</span>
           <span class="code-tag">&lt;artifactId&gt;</span>jaxb-xjc<span
class="code-tag">&lt;/artifactId&gt;</span>
           <span class="code-tag">&lt;version&gt;</span>2.2<span class="code-tag">&lt;/version&gt;</span>
        <span class="code-tag">&lt;/dependency&gt;</span>
     <span class="code-tag">&lt;/dependencies&gt;</span>
<span class="code-tag">&lt;/plugin&gt;</span>

</pre>
</div></div>



<h3><a name="Mavencxf-codegen-plugin%28WSDLtoJava%29-Otherconfigurationoptions"></a>Other
configuration options</h3>

<p>The cxf-codegen-plugin has some additional configuration options that may be useful:</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<td class='confluenceTd'>&lt;fork&gt;false/always/once&lt;/fork&gt;</td>
<td class='confluenceTd'> Forks a separate JVM for the code generation </td>
</tr>
<tr>
<td class='confluenceTd'>&lt;additionalJvmArgs&gt;.... </td>
<td class='confluenceTd'> Additional JVM args set on the forked process if fork is not
false </td>
</tr>
<tr>
<td class='confluenceTd'>&lt;encoding&gt;UTF-8&lt;/encoding&gt;</td>
<td class='confluenceTd'> (new in 2.6.1, requires configuring plugin to use very latest
JAXB 2.2 impl jars)</td>
</tr>
</tbody></table>
</div>


    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CXF20DOC/Maven+cxf-codegen-plugin+%28WSDL+to+Java%29">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=2853210&revisedVersion=14&originalVersion=13">View
Changes</a>
                |
        <a href="https://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