Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Apache CXF as client?

I know how to generate client stubs using Apache CXF. However, when I try to run the generated classes, it uses JAXWS. Also, I notice that the import classes of the generated classes are from the javax package. How can I use set the generated classes to use the Apache CXF libraries instead of the JAXWS libraries?

Below is the code I use to generate the client stubs:

wsdl2java -frontend jaxws21 -wsdlLocation "META-INF/wsdl/WSCustom.wsdl" -client -d C:\Workspace\WSClient\META-INF\wsdl\ "C:\Workspace\WSClient\META-INF\wsdl\WSCustom.wsdl"
like image 916
Arci Avatar asked Mar 04 '13 08:03

Arci


1 Answers

The stubs are correct, there shouldn't be any CXF-specific imports in them because all the information CXF needs can be represented using the JAX-WS standard annotations. At runtime the CXF client libraries will be used if they are on the class path, or the RI ones built in to the JDK will be used if CXF is not available. The generated stubs will work with either.

You asked in the comments about which CXF JARs are required if you're just running a client - as far as I know it's just cxf-rt-frontend-jaxws and cxf-rt-transports-http plus their transitive dependencies. If your project is built with maven then just declare those two dependencies and everything else should come in automatically, if not then download the Apache Ivy main JAR and then run

java -jar ivy-2.3.0.jar -dependency org.apache.cxf cxf-rt-frontend-jaxws 2.7.3 -retrieve "[artifact]-[revision](-[classifier]).jar"
java -jar ivy-2.3.0.jar -dependency org.apache.cxf cxf-rt-transports-http 2.7.3 -retrieve "[artifact]-[revision](-[classifier]).jar"

This should resolve the transitive dependencies and download the relevant JARs from Maven Central into the current directory.

like image 133
Ian Roberts Avatar answered Oct 26 '22 23:10

Ian Roberts