Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: fixed dead link

Maven POM Information

To use CXF within Maven, you'll need to declare the CXF dependencies in your POM. The CXF groupId is "org.apache.cxf". Here is a small example:

Code Block
xml
xml
<properties>
  <cxf.version>2.2.3</cxf.version>
</properties>

<dependencies>
	<dependency>
		<groupId>org.apache.cxf</groupId>
		<artifactId>cxf-rt-frontend-jaxws</artifactId>
		<version>2.0-incubator-RC-SNAPSHOT<<version>${cxf.version}</version>
	</dependency>
	<dependency>
		<groupId>org.apache.cxf</groupId>
		<artifactId>cxf-rt-transports-http</artifactId>
		<version>2.0-incubator-RC-SNAPSHOT<<version>${cxf.version}</version>
	</dependency>
        <!-- Jetty is needed if you're are not using the CXFServlet -->
	<dependency>
		<groupId>org.apache.cxf</groupId>
		<artifactId>cxf-rt-wstransports-http-security<jetty</artifactId>
		<version>2.0-incubator-RC-SNAPSHOT<<version>${cxf.version}</version>
	</dependency>
</dependencies>

You'll also need to add the Apache Incubator Maven repository:

...


<repositories>
	<repository>
		<id>apache-snapshots</id>
		<name>Apache SNAPSHOT Repository</name>
		<url>http://people.apache.org/repo/m2-snapshot-repository/</url>
		<snapshots>
			<enabled>true</enabled>
		</snapshots>
	</repository>
	<repository>
		<id>apache-incubating</id>
		<name>Apache Incubating Repository</name>
		<url>http://people.apache.org/repo/m2-incubating-repository/</url>
	</repository>
</repositories>

<pluginRepositories>
	<pluginRepository>
		<id>apache-plugin-snapshots</id>
		<name>Apache Maven Plugin Snapshots</name>
		<url>http://people.apache.org/repo/m2-snapshot-repository</url>
		<releases>
			<enabled>false</enabled>
		</releases>
		<snapshots>
			<enabled>true</enabled>
		</snapshots>
	</pluginRepository>
</pluginRepositories>

Maven Plugin

CXF includes a Maven plugin which can generate artifacts from WSDL. Here is a simple example:

...

For information on using Maven with CXF and Tomcat, this blog entry may be helpful.

Additional Dependencies

Depending on your usage of CXF, you may need to bring in additional dependencies--the mvn install process will usually make clear what you are missing. Here's a non-exhaustive list of additional CXF artifacts that may be needed:

Code Block
<!-- Use dependency blocks for these CXF artifact Ids just as above -->
cxf-rt-core
cxf-rt-frontend-simple
cxf-rt-frontend-jaxws
cxf-rt-databinding-aegis
cxf-rt-transports-local
cxf-rt-transports-http
cxf-rt-transports-http-jetty
cxf-rt-transports-jms
cxf-rt-management
cxf-common-utilities

Maven Snapshot Repository

To work with the latest non-release versions of CXF (not recommended for production use), updated nightly, change the CXF version to the -SNAPSHOT version desired and add the Apache snapshot repository to both the repositories and pluginRepositories sections:

Code Block
<repositories>
   ...other repos...
   <repository>
      <id>apache-snapshots</id>
      <name>Apache SNAPSHOT Repository</name>
      <url>http://repository.apache.org/snapshots/</url>
      <snapshots>

...


<plugin>
	<groupId>org.apache.cxf</groupId>
	<artifactId>cxf-codegen-plugin</artifactId>
	<version>2.0-incubator-RC-SNAPSHOT</version>
	<executions>
		<execution>
			<id>generate-sources</id>
			<phase>generate-sources</phase>
			<configuration>
				<sourceRoot>${basedir}/target/generated/src/main/java</sourceRoot>
				<wsdlOptions>
					<wsdlOption>
						<wsdl>${basedir}/src/main/wsdl/myService.wsdl</wsdl>
					</wsdlOption>
				</wsdlOptions>
			</configuration>
			<goals>
				<goal>wsdl2java</goal>
			</goals>
		</execution>
	</executions>
</plugin>

In this example we're running the wsdl2java goal in the generate-sources phase. CXF will generate artifacts in the <sourceRoot> directory that you specify. Each <wsdlOption> element corresponds to a WSDL that you're generated artifacts for. In the above example we're generating we're specifying the WSDL location via the <wsdl> option.

Other configuration arguments can be include inside the <wsdlOption> element. These pass arguments to the tooling and correspond to the options outlined on the WSDL To Java page.

Example 1: Passing in a JAX-WS Binding file

Code Block
xmlxml

<configuration>
  <sourceRoot>${basedir}/target/generated/src/main/java</sourceRoot>
  <wsdlOptions>
    <wsdlOption>
      <wsdl>${basedir}/src/main/wsdl/myService.wsdl</wsdl>
      <extraargs>
        <extraarg>-b</extraarg>
        <extraarg>${basedir}/src/main/resources/wsdl/async_binding.xml</extraarg>                              <enabled>true</enabled>
      </extraargs>snapshots>
    </wsdlOption>repository>
  </wsdlOptions>repositories>
</configuration>

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.

Example 2: Specifying a service to generate artifacts for

Code Block
xmlxml

<configuration>
  <sourceRoot>${basedir}/target/generated/src/main/java</sourceRoot>
  <wsdlOptions>
    <wsdlOption>
<pluginRepositories>
   ...other repos...
   <pluginRepository>
      <wsdl>${basedir}/src/main/wsdl/myService.wsdl</wsdl>
      <extraargs>
        <extraarg>-sn</extraarg>
        <extraarg>MyWSDLService</extraarg>                                                                 
      </extraargs>
    </wsdlOption>
  </wsdlOptions>
</configuration>
...same repo as above...
   </pluginRepository>
</pluginRepositories>

The addition to the plugin repositories section is needed because the cxf-codegen-plugin, used for the WSDL2Java, Java2WS, etc. tasks, is downloaded using that entryIn this example we're specifying that we only want to generate artifacts for the service named "MyWSDLService" in the WSDL.