cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "willem jiang (Confluence)" <conflue...@apache.org>
Subject [CONF] Apache CXF Documentation > Maven cxf-codegen-plugin (WSDL to Java)
Date Thu, 04 Jul 2013 01:40:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/en/2176/1/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/~njiang">willem
jiang</a>
    </h4>
        <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;wsdlOption&gt; <br>
	&lt;wsdl&gt;${basedir}/src/main/resources/wsdl/myService.wsdl&lt;/wsdl&gt;
<br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
               &lt;!-- you can set the options of wsdl2java command by using the &lt;extraargs&gt;
--&gt;  <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" >In this example we&#39;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. <br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">h3.
Example 2: Specifying a service to generate artifacts for <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h3.
Example 2: Specify the data binding  <br></td></tr>
            <tr><td class="diff-unchanged" > <br>{code:xml} <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >    &lt;wsdlOption&gt; <br>
     &lt;wsdl&gt;${basedir}/src/main/resources/wsdl/myService.wsdl&lt;/wsdl&gt;
<br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
     &lt;extraargs&gt; <br>        &lt;extraarg&gt;-databinding&lt;/extraarg&gt;
<br>        &lt;extraarg&gt;jibx&lt;/extraarg&gt; <br>      &lt;/extraargs&gt;
<br>    &lt;/wsdlOption&gt; <br>  &lt;/wsdlOptions&gt; <br>&lt;/configuration&gt;
<br>{code} <br> <br>In this example we&#39;re specifying that we want
CXF to use our data binding jibx. You can also using the data binding of xmlbeans, domsources,
sdo etc. <br> <br>h3. Example 3: Specifying a service to generate artifacts for
<br> <br>{code:xml} <br>&lt;configuration&gt; <br>  &lt;wsdlOptions&gt;
<br>    &lt;wsdlOption&gt; <br>      &lt;wsdl&gt;${basedir}/src/main/resources/wsdl/myService.wsdl&lt;/wsdl&gt;
<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" >To avoid copy/paste in multiple &lt;wsdlOption&gt;
you can also declare a &lt;defaultOption&gt; element. <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >h3. Example <span class="diff-changed-words"><span
class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">3</span><span
class="diff-added-chars"style="background-color: #dfd;">4</span>:</span> Using
defaultOption to avoid repetition <br></td></tr>
            <tr><td class="diff-unchanged" > <br>{code:xml} <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >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 <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >h3. Example <span class="diff-changed-words"><span
class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">4</span><span
class="diff-added-chars"style="background-color: #dfd;">5</span>:</span> Using
wsdlRoot with includes/excludes patterns <br></td></tr>
            <tr><td class="diff-unchanged" > <br>{code:xml} <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >wsdlRoot default value is {{src/main/resources/wsdl}}
so you may omit this declaration. <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >h3. Example <span class="diff-changed-words"><span
class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">5</span><span
class="diff-added-chars"style="background-color: #dfd;">6</span>:</span> Loading
a wsdl from the maven repository <br></td></tr>
            <tr><td class="diff-unchanged" > <br>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. <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >This will load the wsdl /org/apache/pizza/PizzaService-1.0.0.wsdl
into your local maven repository and generate java code from it. <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >h3. Example <span class="diff-changed-words"><span
class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">6</span><span
class="diff-added-chars"style="background-color: #dfd;">7</span>:</span> Using
xjc extensions <br></td></tr>
            <tr><td class="diff-unchanged" > <br>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;  <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >h3. Example <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">7</span>
<span class="diff-added-words"style="background-color: #dfd;">8</span> - Using
JAXB/JAX-WS 2.2 with Java 6 <br></td></tr>
            <tr><td class="diff-unchanged" > <br>Java 6 includes JAXB/JAX-WS
2.1 API&#39;s and a 2.1 implementations.  However, sometimes it&#39;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 &quot;forking&quot;, etc... 
 First off, both Surefire and the Compiler plugins need to be setup to point at an endorsed
dir: <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="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
&lt;plugin&gt;
	&lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
	&lt;artifactId&gt;cxf-codegen-plugin&lt;/artifactId&gt;
	&lt;version&gt;${cxf.version}&lt;/version&gt;
	&lt;executions&gt;
		&lt;execution&gt;
			&lt;id&gt;generate-sources&lt;/id&gt;
			&lt;phase&gt;generate-sources&lt;/phase&gt;
			&lt;configuration&gt;
				&lt;sourceRoot&gt;${project.build.directory}/generated/cxf&lt;/sourceRoot&gt;
				&lt;wsdlOptions&gt;
					&lt;wsdlOption&gt;
						&lt;wsdl&gt;${basedir}/src/main/resources/myService.wsdl&lt;/wsdl&gt;
					&lt;/wsdlOption&gt;
				&lt;/wsdlOptions&gt;
			&lt;/configuration&gt;
			&lt;goals&gt;
				&lt;goal&gt;wsdl2java&lt;/goal&gt;
			&lt;/goals&gt;
		&lt;/execution&gt;
	&lt;/executions&gt;
&lt;/plugin&gt;
</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="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
...
&lt;configuration&gt;
    &lt;sourceRoot&gt;${project.build.directory}/generated-code/mywebservice&lt;/sourceRoot&gt;
    &lt;wsdlOptions&gt;
	&lt;wsdlOption&gt;
		&lt;wsdl&gt;${basedir}/src/main/resources/wsdl/myService.wsdl&lt;/wsdl&gt;
                &lt;!-- you can set the options of wsdl2java command by using the &lt;extraargs&gt;
--&gt; 
                &lt;extraargs&gt;
                    &lt;extraarg&gt;-impl&lt;/extraarg&gt;
                    &lt;extraarg&gt;-verbose&lt;/extraarg&gt;
                &lt;/extraargs&gt;
	&lt;/wsdlOption&gt;
    &lt;/wsdlOptions&gt;
&lt;/configuration&gt;
...
</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="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
&lt;configuration&gt;
  &lt;wsdlOptions&gt;
    &lt;wsdlOption&gt;
      &lt;wsdl&gt;${basedir}/src/main/resources/wsdl/myService.wsdl&lt;/wsdl&gt;
      &lt;bindingFiles&gt;
        &lt;bindingFile&gt;${basedir}/src/main/resources/async_binding.xml&lt;/bindingFile&gt;
      &lt;/bindingFiles&gt;
    &lt;/wsdlOption&gt;
  &lt;/wsdlOptions&gt;
&lt;/configuration&gt;
</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%3ASpecifythedatabinding"></a>Example
2: Specify the data binding </h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
&lt;configuration&gt;
  &lt;wsdlOptions&gt;
    &lt;wsdlOption&gt;
      &lt;wsdl&gt;${basedir}/src/main/resources/wsdl/myService.wsdl&lt;/wsdl&gt;
      &lt;extraargs&gt;
        &lt;extraarg&gt;-databinding&lt;/extraarg&gt;
        &lt;extraarg&gt;jibx&lt;/extraarg&gt;
      &lt;/extraargs&gt;
    &lt;/wsdlOption&gt;
  &lt;/wsdlOptions&gt;
&lt;/configuration&gt;
</pre>
</div></div>

<p>In this example we're specifying that we want CXF to use our data binding jibx. You
can also using the data binding of xmlbeans, domsources, sdo etc.</p>

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

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
&lt;configuration&gt;
  &lt;wsdlOptions&gt;
    &lt;wsdlOption&gt;
      &lt;wsdl&gt;${basedir}/src/main/resources/wsdl/myService.wsdl&lt;/wsdl&gt;
      &lt;serviceName&gt;MyWSDLService&lt;/serviceName&gt;
    &lt;/wsdlOption&gt;
  &lt;/wsdlOptions&gt;
&lt;/configuration&gt;
</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-Example4%3AUsingdefaultOptiontoavoidrepetition"></a>Example
4: Using defaultOption to avoid repetition</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
&lt;configuration&gt;
  &lt;defaultOptions&gt;
      &lt;bindingFiles&gt;
          &lt;bindingFile&gt;${basedir}/src/main/jaxb/bindings.xml&lt;/bindingFile&gt;
      &lt;/bindingFiles&gt;
      &lt;noAddressBinding&gt;true&lt;/noAddressBinding&gt;
  &lt;/defaultOptions&gt;
  &lt;wsdlOptions&gt;
      &lt;wsdlOption&gt;
          &lt;wsdl&gt;${basedir}/src/main/resources/wsdl/myService.wsdl&lt;/wsdl&gt;
          &lt;serviceName&gt;MyWSDLService&lt;/serviceName&gt;
      &lt;/wsdlOption&gt;
      &lt;wsdlOption&gt;
          &lt;wsdl&gt;${basedir}/src/main/resources/wsdl/myOtherService.wsdl&lt;/wsdl&gt;
          &lt;serviceName&gt;MyOtherWSDLService&lt;/serviceName&gt;
      &lt;/wsdlOption&gt;
  &lt;/wsdlOptions&gt;
&lt;/configuration&gt;
</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-Example5%3AUsingwsdlRootwithincludes%2Fexcludespatterns"></a>Example
5: Using wsdlRoot with includes/excludes patterns</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
&lt;configuration&gt;
  &lt;defaultOptions&gt;
      &lt;bindingFiles&gt;
          &lt;bindingFile&gt;${basedir}/src/main/jaxb/bindings.xml&lt;/bindingFile&gt;
      &lt;/bindingFiles&gt;
      &lt;noAddressBinding&gt;true&lt;/noAddressBinding&gt;
  &lt;/defaultOptions&gt;
  &lt;wsdlRoot&gt;${basedir}/src/main/resources/wsdl&lt;/wsdlRoot&gt;
  &lt;includes&gt;
      &lt;include&gt;*Service.wsdl&lt;/include&gt;
  &lt;/includes&gt;
&lt;/configuration&gt;
</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-Example6%3ALoadingawsdlfromthemavenrepository"></a>Example
6: 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="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
    &lt;configuration&gt;
     &lt;wsdlOptions&gt;
      &lt;wsdlOption&gt;
       &lt;wsdlArtifact&gt;
        &lt;groupId&gt;org.apache.pizza&lt;/groupId&gt;
	&lt;artifactId&gt;PizzaService&lt;/artifactId&gt;
	&lt;version&gt;1.0.0&lt;/version&gt;
       &lt;/wsdlArtifact&gt;
      &lt;/wsdlOption&gt;
     &lt;/wsdlOptions&gt;
    &lt;/configuration&gt;
</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-Example7%3AUsingxjcextensions"></a>Example
7: 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="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
&lt;plugin&gt;
&lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
&lt;artifactId&gt;cxf-codegen-plugin&lt;/artifactId&gt;
&lt;version&gt;${cxf.version}&lt;/version&gt;
&lt;executions&gt;
  &lt;execution&gt;
    &lt;id&gt;generate-sources&lt;/id&gt;
    &lt;phase&gt;generate-sources&lt;/phase&gt;
    &lt;configuration&gt;
      &lt;wsdlOptions&gt;
        &lt;wsdlOption&gt;
          &lt;wsdl&gt;${basedir}/src/main/resources/wsdl/myService.wsdl&lt;/wsdl&gt;
          &lt;extraargs&gt;
            &lt;extraarg&gt;-xjc-b,binding.xjb&lt;/extraarg&gt;
            &lt;extraarg&gt;-xjc-Xts&lt;/extraarg&gt;
          &lt;/extraargs&gt; 
        &lt;/wsdlOption&gt;
      &lt;/wsdlOptions&gt;
    &lt;/configuration&gt;
    &lt;goals&gt;
      &lt;goal&gt;wsdl2java&lt;/goal&gt;
    &lt;/goals&gt;
  &lt;/execution&gt;
&lt;/executions&gt;
&lt;dependencies&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
        &lt;artifactId&gt;cxf-xjc-ts&lt;/artifactId&gt;
        &lt;version&gt;${cxf.version}&lt;/version&gt;
     &lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;/plugin&gt;
</pre>
</div></div>


<h3><a name="Mavencxf-codegen-plugin%28WSDLtoJava%29-Example8UsingJAXB%2FJAXWS2.2withJava6"></a>Example
8 - 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="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">

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

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

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
&lt;plugins&gt;
    &lt;plugin&gt;
       &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
       &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
       &lt;executions&gt;
          &lt;execution&gt;
             &lt;phase&gt;generate-sources&lt;/phase&gt;
             &lt;goals&gt;
                 &lt;goal&gt;copy&lt;/goal&gt;
             &lt;/goals&gt;
             &lt;configuration&gt;
                 &lt;artifactItems&gt;
                    &lt;artifactItem&gt;
                       &lt;groupId&gt;javax.xml.bind&lt;/groupId&gt;
                       &lt;artifactId&gt;jaxb-api&lt;/artifactId&gt;
                       &lt;version&gt;2.2&lt;/version&gt;
                    &lt;/artifactItem&gt;
                    &lt;artifactItem&gt;
                       &lt;groupId&gt;javax.xml.ws&lt;/groupId&gt;
                       &lt;artifactId&gt;jaxws-api&lt;/artifactId&gt;
                       &lt;version&gt;2.2&lt;/version&gt;
                    &lt;/artifactItem&gt;
                  &lt;/artifactItems&gt;
                  &lt;outputDirectory&gt;${project.build.directory}/endorsed&lt;/outputDirectory&gt;
              &lt;/configuration&gt;
           &lt;/execution&gt;
       &lt;/executions&gt;
    &lt;/plugin&gt;
&lt;/plugins&gt;

</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="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">

&lt;plugin&gt;
    &lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
    &lt;artifactId&gt;cxf-codegen-plugin&lt;/artifactId&gt;
    &lt;version&gt;${cxf.version}&lt;/version&gt;
    &lt;configuration&gt;
        &lt;fork&gt;once&lt;/fork&gt;
        &lt;additionalJvmArgs&gt;-Djava.endorsed.dirs=${project.build.directory}/endorsed&lt;/additionalJvmArgs&gt;
        &lt;!-- rest of the normal codegen configuration options --&gt;
    &lt;/configuraion&gt;
    &lt;dependencies&gt;
        &lt;dependency&gt;
           &lt;groupId&gt;com.sun.xml.bind&lt;/groupId&gt;
           &lt;artifactId&gt;jaxb-impl&lt;/artifactId&gt;
           &lt;version&gt;2.2&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
           &lt;groupId&gt;com.sun.xml.bind&lt;/groupId&gt;
           &lt;artifactId&gt;jaxb-xjc&lt;/artifactId&gt;
           &lt;version&gt;2.2&lt;/version&gt;
        &lt;/dependency&gt;
     &lt;/dependencies&gt;
&lt;/plugin&gt;

</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;" class="grey">
                        <a href="https://cwiki.apache.org/confluence/users/removespacenotification.action?spaceKey=CXF20DOC">Stop
watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://cwiki.apache.org/confluence/users/editmyemailsettings.action">Change
email 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=17&originalVersion=16">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