Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this example we're running the wsdl2java goal in the generate-sources phase. By running mvn generate-sources, CXF will generate artifacts in the <sourceRoot> directory that you specify. Each <wsdlOption> element corresponds to a WSDL that you're generated generating artifacts for. The WSDL location is specified via the <wsdl> option. Following Maven standard directory layout, 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.

...

Code Block
languagexml
...
<configuration>
    <sourceRoot>${project.build.directory}/generated-code/mywebservice</sourceRoot>
    <wsdlOptions>
	    <wsdlOption>
		    <wsdl>${basedir}/src/main/resources/wsdl/myService.wsdl</wsdl>
                <!-- you can set the options of wsdl2java command by using the <extraargs> --> 
                <extraargs>
                    <extraarg>-impl</extraarg>
                    <extraarg>-verbose</extraarg>
                </extraargs>
	    </wsdlOption>
    </wsdlOptions>
</configuration>
...

...

To avoid copy/paste in multiple <wsdlOption> you can also declare a <defaultOption> <defaultOptions> element.

Example 4: Using defaultOption to avoid repetition

Code Block
languagexml
<configuration>
  <defaultOptions>
      <bindingFiles>
          <bindingFile>${basedir}/src/main/jaxb/bindings.xml</bindingFile>
      </bindingFiles>
      <noAddressBinding>true</noAddressBinding>
  </defaultOptions>
  <wsdlOptions>
      <wsdlOption>
          <wsdl>${basedir}/src/main/resources/wsdl/myService.wsdl</wsdl>
          <serviceName>MyWSDLService</serviceName>
      </wsdlOption>
      <wsdlOption>
          <wsdl>${basedir}/src/main/resources/wsdl/myOtherService.wsdl</wsdl>
          <serviceName>MyOtherWSDLService</serviceName>
      </wsdlOption>
  </wsdlOptions>
</configuration>

<defaultOption> <defaultOptions> and <wsdlOption> correspond to the options outlined on the WSDL to Java page, you may look at https://github.com/apache/cxf/blob/master/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/Option.java for a more detailed description of those parameters.

...

There is a <wsdlArtifact> wsdlOption configuration which can be used to load a wsdl file from the maven repository.

Code Block
languagexml
<configuration>
    <configuration><wsdlOptions>
        <wsdlOptions>
<wsdlOption>
            <wsdlOption><wsdlArtifact>
        <wsdlArtifact>
        <groupId>org.apache.pizza</groupId>
	    <artifactId>PizzaService<        <artifactId>PizzaService</artifactId>
	            <version>1.0.0</version>
            </wsdlArtifact>
        </wsdlOption>
     </wsdlOptions>
    </configuration>

This will load the wsdl /org/apache/pizza/PizzaService-1.0.0.wsdl into your local maven repository and generate java code from it.

...

Code Block
languagexml
<plugin>
  <groupId>org.apache.cxf</groupId>
  <artifactId>cxf-codegen-plugin</artifactId>
  <version>${cxf.version}</version>
  <executions>
    <execution>
      <id>generate-sources</id>
      <phase>generate-sources</phase>
      <configuration>
        <wsdlOptions>
          <wsdlOption>
            <wsdl>${basedir}/src/main/resources/wsdl/myService.wsdl</wsdl>
            <extraargs>
              <extraarg>-xjc-Xts</extraarg>
            </extraargs> 
          </wsdlOption>
        </wsdlOptions>
      </configuration>
      <goals>
        <goal>wsdl2java</goal>
      </goals>
    </execution>
  </executions>
  <dependencies>
    <dependency>
        <groupId>org.apache.cxf.xjcplugins</groupId>
        <artifactId>cxf-xjc-ts</artifactId>
        <version>${cxf-xjc.version}</version>
     </dependency>
  </dependencies>
</plugin>

...