I recently created some SOAP web service clients using Apache CXF (which is a project that resulted from the merging of XFire and Celtix). Rather than hunt down all the jar files I needed and write an Ant script to do the build, I decided to use Maven for this. It worked nicely and saved me some time (I can’t say the same for some of the more complex projects I’ve tried to use Maven with).
I found the following blog entry very useful for setting this up:
How to create a WSDL-first SOAP client in Java with CXF and Maven
One thing I did different was use a property to specify the CXF version in one place:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cxf.version>2.2.1</cxf.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
Pay attention to what it says about the cxf.xml
file. I used the Maven Eclipse Plugin to generate my Eclipse project files. If you do this, but forget the cxf.xml file, your client may still work fine in Eclipse, but when you try to use the Maven-built jar file, you will get an error like this:
javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException
at org.apache.cxf.jaxws.ServiceImpl.getPort(ServiceImpl.java:314)
at org.apache.cxf.jaxws.ServiceImpl.getPort(ServiceImpl.java:299)
at javax.xml.ws.Service.getPort(Service.java:40)
...
Caused by: org.apache.cxf.service.factory.ServiceConstructionException
at org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:59)
at org.apache.cxf.frontend.ClientProxyFactoryBean.create(ClientProxyFactoryBean.java:102)
at org.apache.cxf.jaxws.JaxWsProxyFactoryBean.create(JaxWsProxyFactoryBean.java:115)
at org.apache.cxf.jaxws.ServiceImpl.createPort(ServiceImpl.java:434)
at org.apache.cxf.jaxws.ServiceImpl.getPort(ServiceImpl.java:312)
... 33 more
Caused by: org.apache.cxf.BusException: No binding factory for namespace http://schemas.xmlsoap.org/wsdl/soap/ registered.
...
So make sure to put the cxf.xml
file in your src/main/resources
folder (create that folder if it doesn’t exist).
© 2017 Nilesh D Kapadia