I am trying to generate a webservice client with the wsdl2java
goal of the Apache CXF Maven Plugin. I have a WSDL URL link, but when using the Maven plugin, it is not generating the sources. Sample WSDL link is http://www.webservicex.com/globalweather.asmx?WSDL.
<properties>
<src.generated.dir>src/main/java</src.generated.dir>
<artifact.cxf.version>3.1.6 </artifact.cxf.version>
<xerces.version>2.11.0</xerces.version>
<inbound.wsdl>http://www.webservicex.com/globalweather.asmx?WSDL</inbound.wsdl>
<inbound.wsdl.location>http://www.webservicex.com/globalweather.asmx?WSDL</inbound.wsdl.location>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${artifact.cxf.version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${src.generated.dir}</sourceRoot>
<defaultOptions>
<noAddressBinding>true</noAddressBinding>
<faultSerialVersionUID>3105839350746982386</faultSerialVersionUID>
</defaultOptions>
<wsdlOptions>
<wsdlOption>
<wsdl>${inbound.wsdl}</wsdl>
<wsdlLocation>${inbound.wsdl.location}</wsdlLocation>
<serviceName>webservicex</serviceName>
<extraargs>
<extraarg>-client</extraarg>
<extraarg>-verbose</extraarg>
<extraarg>-p</extraarg>
<extraarg>http://webservicex.ent.com/arm/=com.ent.webservicex.arm</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>${xerces.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
The problem is not related to the use of a HTTP link to a WSDL file. The error that the CXF Codegen Plugin returns is:
No service was found in wsdl:
webservicex
This is normal because the WSDL hosted at http://www.webservicex.com/globalweather.asmx?WSDL
only has a single service named GlobalWeather
; it does not have a service called webservicex
. A service definition in a WSDL corresponds to a wsdl:service
element, and if you peek into the WSDL, you'll only see
<wsdl:service name="GlobalWeather">
<!-- ... -->
</wsdl:service>
Thus, you should change your CXF configuration to
<serviceName>GlobalWeather</serviceName>
or even omit the parameter completely and let the plugin generate it automatically (since there's only one service).
There are other related notes with your current configuration that it would be best to change:
Never, ever, generate code inside the main source directory src/main/java
, as it is currently done with
<src.generated.dir>src/main/java</src.generated.dir>
Generated code should always be placed under the build directory (i.e. target
by default). This is because generated code is not a real source file and should not be checked in on version-control. By default, this is what the plugin is doing, generating code in target/generated-sources/cxf
, and I suggest you keep with that; as such, you just need to remove <sourceRoot>${src.generated.dir}</sourceRoot>
. It also automatically adds the generated source code as a source folder, so everything will still compile.
You do not need the xerces
dependency for the plugin to work, you can remove the whole <dependencies>
section of the plugin.
There is no <wsdlLocation>
parameter, so you can remove that as well, it doesn't do anything.