blob: e5edcbb0f72798fbcf31aa9d0122c4cf4cbdb610 [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
<link type="text/css" rel="stylesheet" href="/resources/site.css">
<script src='/resources/space.js'></script>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<meta name="keywords" content="business integration, EAI, SOA, Service Oriented Architecture, web services, SOAP, JBI, JMS, WSDL, XML, EDI, Electronic Data Interchange, standards support, integration standards, application integration, middleware, software, solutions, services, CXF, open source">
<meta name="description" content="Apache CXF, Services Framework - Maven cxf-codegen-plugin (WSDL to Java)">
<link type="text/css" rel="stylesheet" href="/resources/highlighter/styles/shCoreCXF.css">
<link type="text/css" rel="stylesheet" href="/resources/highlighter/styles/shThemeCXF.css">
<script src='/resources/highlighter/scripts/shCore.js'></script>
<script src='/resources/highlighter/scripts/shBrushBash.js'></script>
<script src='/resources/highlighter/scripts/shBrushXml.js'></script>
<script src='/resources/highlighter/scripts/shBrushJava.js'></script>
<script>
SyntaxHighlighter.defaults['toolbar'] = false;
SyntaxHighlighter.all();
</script>
<title>
Apache CXF -- Maven cxf-codegen-plugin (WSDL to Java)
</title>
</head>
<body onload="init()">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td id="cell-0-0" colspan="2">&nbsp;</td>
<td id="cell-0-1">&nbsp;</td>
<td id="cell-0-2" colspan="2">&nbsp;</td>
</tr>
<tr>
<td id="cell-1-0">&nbsp;</td>
<td id="cell-1-1">&nbsp;</td>
<td id="cell-1-2">
<!-- Banner -->
<div class="banner" id="banner"><div><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td align="left" colspan="1" nowrap>
<a shape="rect" href="http://cxf.apache.org/" title="Apache CXF"><span style="font-weight: bold; font-size: 170%; color: white">Apache CXF</span></a>
</td><td align="right" colspan="1" nowrap>
<a shape="rect" href="http://www.apache.org/" title="The Apache Sofware Foundation"><img border="0" alt="ASF Logo" src="http://cxf.apache.org/images/asf-logo.png"></a>
</td></tr></table></div></div>
<!-- Banner -->
<div id="top-menu">
<table border="0" cellpadding="1" cellspacing="0" width="100%">
<tr>
<td>
<div align="left">
<!-- Breadcrumbs -->
<a href="index.html">Index</a>&nbsp;&gt;&nbsp;<a href="tools.html">Tools</a>&nbsp;&gt;&nbsp;<a href="maven-cxf-codegen-plugin-wsdl-to-java.html">Maven cxf-codegen-plugin (WSDL to Java)</a>
<!-- Breadcrumbs -->
</div>
</td>
<td>
<div align="right">
<!-- Quicklinks -->
<div id="quicklinks"><p><a shape="rect" href="http://cxf.apache.org/download.html">Download</a> | <a shape="rect" href="http://cxf.apache.org/docs/index.html">Documentation</a></p></div>
<!-- Quicklinks -->
</div>
</td>
</tr>
</table>
</div>
</td>
<td id="cell-1-3">&nbsp;</td>
<td id="cell-1-4">&nbsp;</td>
</tr>
<tr>
<td id="cell-2-0" colspan="2">&nbsp;</td>
<td id="cell-2-1">
<table>
<tr valign="top">
<td height="100%">
<div id="wrapper-menu-page-right">
<div id="wrapper-menu-page-top">
<div id="wrapper-menu-page-bottom">
<div id="menu-page">
<!-- NavigationBar -->
<div id="navigation"><ul class="alternate"><li><a shape="rect" href="overview.html">Overview</a></li><li><a shape="rect" href="how-tos.html">How-Tos</a></li><li><a shape="rect" href="frontends.html">Frontends</a></li><li><a shape="rect" href="databindings.html">DataBindings</a></li><li><a shape="rect" href="transports.html">Transports</a></li><li><a shape="rect" href="configuration.html">Configuration</a></li><li><a shape="rect" href="debugging-and-logging.html">Debugging and Logging</a></li><li><a shape="rect" href="tools.html">Tools</a></li><li><a shape="rect" href="restful-services.html">RESTful Services</a></li><li><a shape="rect" href="wsdl-bindings.html">WSDL Bindings</a></li><li><a shape="rect" href="service-routing.html">Service Routing</a></li><li><a shape="rect" href="dynamic-languages.html">Dynamic Languages</a></li><li><a shape="rect" href="ws-support.html">WS-* Support</a></li><li><a shape="rect" href="advanced-integration.html">Advanced Integration</a></li><li><a shape="rect" href="deployment.html">Deployment</a></li><li><a shape="rect" href="schemas-and-namespaces.html">Use of Schemas and Namespaces</a></li></ul><hr><ul class="alternate"><li><p>Search</p></li></ul><form enctype="application/x-www-form-urlencoded" method="get" id="cse-search-box" action="http://www.google.com/cse">
<div>
<input type="hidden" name="cx" value="002890367768291051730:o99qiwa09y4">
<input type="hidden" name="ie" value="UTF-8">
<input type="text" name="q" size="21">
<input type="submit" name="sa" value="Search">
</div>
</form>
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&amp;lang=en"></script><hr><ul class="alternate"><li><a shape="rect" href="http://cxf.apache.org/javadoc/latest/">API 3.2.x (Javadoc)</a></li><li><a shape="rect" href="http://cxf.apache.org/javadoc/latest-3.1.x/">API 3.1.x (Javadoc)</a></li><li><a shape="rect" href="http://cxf.apache.org/">CXF Website</a></li></ul><p>&#160;</p><p><a shape="rect" class="external-link" href="http://www.apache.org/events/current-event.html"><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-external-resource" src="http://www.apache.org/events/current-event-125x125.png" data-image-src="http://www.apache.org/events/current-event-125x125.png"></span></a></p></div>
<!-- NavigationBar -->
</div>
</div>
</div>
</div>
</td>
<td height="100%">
<!-- Content -->
<div class="wiki-content">
<div id="ConfluenceContent"><p><style type="text/css">/*<![CDATA[*/
div.rbtoc1636141578578 {padding: 0px;}
div.rbtoc1636141578578 ul {list-style: disc;margin-left: 0px;}
div.rbtoc1636141578578 li {margin-left: 0px;padding-left: 0px;}
/*]]>*/</style></p><div class="toc-macro rbtoc1636141578578">
<ul class="toc-indentation"><li><a shape="rect" href="#Mavencxfcodegenplugin(WSDLtoJava)-Introduction">Introduction</a></li><li><a shape="rect" href="#Mavencxfcodegenplugin(WSDLtoJava)-Example1:PassinginaJAX-WSBindingfile">Example 1: Passing in a JAX-WS Binding file</a></li><li><a shape="rect" href="#Mavencxfcodegenplugin(WSDLtoJava)-Example2:Specifythedatabinding">Example 2: Specify the data binding</a></li><li><a shape="rect" href="#Mavencxfcodegenplugin(WSDLtoJava)-Example3:Specifyingaservicetogenerateartifactsfor">Example 3: Specifying a service to generate artifacts for</a></li><li><a shape="rect" href="#Mavencxfcodegenplugin(WSDLtoJava)-Example4:UsingdefaultOptiontoavoidrepetition">Example 4: Using defaultOption to avoid repetition</a></li><li><a shape="rect" href="#Mavencxfcodegenplugin(WSDLtoJava)-Example5:UsingwsdlRootwithincludes/excludespatterns">Example 5: Using wsdlRoot with includes/excludes patterns</a></li><li><a shape="rect" href="#Mavencxfcodegenplugin(WSDLtoJava)-Example6:Loadingawsdlfromthemavenrepository">Example 6: Loading a wsdl from the maven repository</a></li><li><a shape="rect" href="#Mavencxfcodegenplugin(WSDLtoJava)-Example7:Usingxjcextensions">Example 7: Using xjc extensions</a></li><li><a shape="rect" href="#Mavencxfcodegenplugin(WSDLtoJava)-Example8-UsingJAXB/JAX-WS2.2withJava6">Example 8 - Using JAXB/JAX-WS 2.2 with Java 6</a></li><li><a shape="rect" href="#Mavencxfcodegenplugin(WSDLtoJava)-ReadingexternalDTDs">Reading external DTDs</a></li><li><a shape="rect" href="#Mavencxfcodegenplugin(WSDLtoJava)-Otherconfigurationoptions">Other configuration options</a></li></ul>
</div><h3 id="Mavencxfcodegenplugin(WSDLtoJava)-Introduction">Introduction</h3><p>CXF includes a Maven plugin which can generate java artifacts from WSDL. Here is a simple example:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default">&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-sources/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 <strong>mvn generate-sources</strong>, 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 generating artifacts for. The WSDL location is specified via the &lt;wsdl&gt; option. Following <a shape="rect" class="external-link" href="http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html">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 shape="rect" href="wsdl-to-java.html">WSDL to Java</a> page.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default">...
&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 shape="rect" class="external-link" href="https://glenmazza.net/blog/entry/web-service-tutorial" rel="nofollow">this blog entry</a> for a full service and client example that uses the cxf-codegen-plugin.</p><h3 id="Mavencxfcodegenplugin(WSDLtoJava)-Example1:PassinginaJAX-WSBindingfile">Example 1: Passing in a JAX-WS Binding file</h3><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default">&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 id="Mavencxfcodegenplugin(WSDLtoJava)-Example2:Specifythedatabinding">Example 2: Specify the data binding</h3><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default">&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 id="Mavencxfcodegenplugin(WSDLtoJava)-Example3:Specifyingaservicetogenerateartifactsfor">Example 3: Specifying a service to generate artifacts for</h3><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default">&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;defaultOptions&gt; element.</p><h3 id="Mavencxfcodegenplugin(WSDLtoJava)-Example4:UsingdefaultOptiontoavoidrepetition">Example 4: Using defaultOption to avoid repetition</h3><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default">&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;defaultOptions&gt; and &lt;wsdlOption&gt; correspond to the options outlined on the <a shape="rect" href="wsdl-to-java.html">WSDL to Java</a> page, you may look at&#160;<a shape="rect" class="external-link" href="https://github.com/apache/cxf/blob/master/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/Option.java" rel="nofollow">https://github.com/apache/cxf/blob/master/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/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 id="Mavencxfcodegenplugin(WSDLtoJava)-Example5:UsingwsdlRootwithincludes/excludespatterns">Example 5: Using wsdlRoot with includes/excludes patterns</h3><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default">&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 <code>src/main/resources/wsdl</code> so you may omit this declaration.</p><h3 id="Mavencxfcodegenplugin(WSDLtoJava)-Example6:Loadingawsdlfromthemavenrepository">Example 6: Loading a wsdl from the maven repository</h3><p>There is a &lt;wsdlArtifact&gt; wsdlOption configuration which can be used to load a wsdl file from the maven repository.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default">&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 id="Mavencxfcodegenplugin(WSDLtoJava)-Example7:Usingxjcextensions">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. <a shape="rect" href="../xjc-utils.html">CXF also offers some JAXB extensions for the code generation</a>. 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 colspan="1" rowspan="1" class="confluenceTh"><p>artifact id</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>description</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>extension id</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>cxf-xjc-boolean</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Adds getters for booleans</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>boolean</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>cxf-xjc-bug671</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Workaroung for JAXB bug 671</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>bug671</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>cxf-xjc-dv</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Default value support</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>dv</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>cxf-xjc-ts</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Adds toString to objects</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>ts</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>cxf-xjc-wsdlextension</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>WsdlExtension support</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>wsdlextension</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>jaxb-fluent-api</p><p>(<img class="emoticon emoticon-warning" src="https://cwiki.apache.org/confluence/s/9h3cbz/8703/189cb2l/_/images/icons/emoticons/warning.svg" data-emoticon-name="warning" alt="(warning)"> not part of CXF:</p><p>group id is net.java.dev.jaxb2-commons)</p></td><td colspan="1" rowspan="1" class="confluenceTd">Fluent API for setters</td><td colspan="1" rowspan="1" 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 pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default">&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-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.xjcplugins&lt;/groupId&gt;
&lt;artifactId&gt;cxf-xjc-ts&lt;/artifactId&gt;
&lt;version&gt;${cxf-xjc.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;/plugin&gt;
</pre>
</div></div><p>In addition you need to add the cxf-xjc-runtime as a dependency to your project:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default">&lt;dependency&gt;
&lt;groupId&gt;org.apache.cxf.xjc-utils&lt;/groupId&gt;
&lt;artifactId&gt;cxf-xjc-runtime&lt;/artifactId&gt;
&lt;version&gt;${cxf-xjc.version}&lt;/version&gt;
&lt;/dependency&gt;</pre>
</div></div><h3 id="Mavencxfcodegenplugin(WSDLtoJava)-Example8-UsingJAXB/JAX-WS2.2withJava6">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 pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default">&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 pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default">&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 pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default">&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;/configuration&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.11&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.11&lt;/version&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;/plugin&gt;
</pre>
</div></div><h3 id="Mavencxfcodegenplugin(WSDLtoJava)-ReadingexternalDTDs">Reading external DTDs</h3><p>More recent versions of XML Schema will throw an exception by default if the schema has an external DTD. For example:</p><p>[Fatal Error] xmldsig-core-schema.xsd:10:5: External DTD: Failed to read external DTD 'XMLSchema.dtd', because 'http' access is not allowed due to restriction set by the accessExternalDTD property.</p><p>If you wish to allow external DTDs then it's possible to do this via the the &lt;additionalJvmArgs&gt;' configuration switch as follows:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default">&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;phase&gt;generate-sources&lt;/phase&gt;
&lt;configuration&gt;
&lt;fork&gt;once&lt;/fork&gt;
&lt;wsdlOptions&gt;
&lt;wsdlOption&gt;
&lt;wsdl&gt;${basedir}/src/main/resources/org/apache/cxf/wsn/wsdl/wsn.wsdl&lt;/wsdl&gt;
&lt;extraargs&gt;
&lt;extraarg&gt;-verbose&lt;/extraarg&gt;
&lt;/extraargs&gt;
&lt;/wsdlOption&gt;
&lt;/wsdlOptions&gt;
&lt;additionalJvmArgs&gt;-Djavax.xml.accessExternalDTD=all&lt;/additionalJvmArgs&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><br clear="none"></p><h3 id="Mavencxfcodegenplugin(WSDLtoJava)-Otherconfigurationoptions">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"><colgroup span="1"><col span="1"><col span="1"></colgroup><tbody><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>&lt;fork&gt;false/always/once&lt;/fork&gt;</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Forks a separate JVM for the code generation</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>&lt;additionalJvmArgs&gt;....</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Additional JVM args set on the forked process if fork is not false</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>&lt;encoding&gt;UTF-8&lt;/encoding&gt;</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>(new in 2.6.1, requires configuring plugin to use very latest JAXB 2.2.11 impl jars)</p></td></tr></tbody></table></div></div>
</div>
<!-- Content -->
</td>
</tr>
</table>
</td>
<td id="cell-2-2" colspan="2">&nbsp;</td>
</tr>
<tr>
<td id="cell-3-0">&nbsp;</td>
<td id="cell-3-1">&nbsp;</td>
<td id="cell-3-2">
<div id="footer">
<!-- Footer -->
<div id="site-footer">
<a href="http://cxf.apache.org/privacy-policy.html">Privacy Policy</a> -
(<a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=2853210">edit page</a>)
(<a href="https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=2853210&amp;showComments=true&amp;showCommentArea=true#addcomment">add comment</a>)<br>
Apache CXF, CXF, Apache, the Apache feather logo are trademarks of The Apache Software Foundation.<br>
All other marks mentioned may be trademarks or registered trademarks of their respective owners.
</div>
<!-- Footer -->
</div>
</td>
<td id="cell-3-3">&nbsp;</td>
<td id="cell-3-4">&nbsp;</td>
</tr>
<tr>
<td id="cell-4-0" colspan="2">&nbsp;</td>
<td id="cell-4-1">&nbsp;</td>
<td id="cell-4-2" colspan="2">&nbsp;</td>
</tr>
</table>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-4458903-1");
pageTracker._trackPageview();
} catch(err) {}</script>
</body>
</html>