I have created a web service with apache-cxf-2.7.4. I entered the classes produced in my project. the libraries I have in my project are:
- math3-commons-3.2.jar
- XStream-1.4.4.jar
- jaxws-api-2.2.5.jar
I have the following error:
constructor Service in class javax.xml.ws.Service cannot be applied to given types;
required: java.net.URL,javax.xml.namespace.QName
found: java.net.URL,javax.xml.namespace.QName,javax.xml.ws.WebServiceFeature[]
reason: actual and formal argument lists differ in length
If using Maven to build you should add this to the execution configuration
(thanks to Paul Vargas for pointing me in the right direction).
The problem is the version of JAX-WS API. The classloader for your application first loaded the version included in Java SE or Java EE.
For Java SE 6 or Java EE 5, JAX-WS API 2.1. The constructors in
javax.xml.ws.Service
:For Java SE 7 or Java EE 6, JAX-WS API 2.2. The constructors in
javax.xml.ws.Service
:There are three possible solutions (depends on whether it is a web application or standalone application):
Use Java SE 7 or Java EE 6.
Re-run
wsdl2java
with argument-frontend jaxws21
to generate JAX-WS 2.1 compliant code instead.Change the classloader for load first the classes included in the application.
wsimport -help tells us about the -target option. It says: Generate code as per the given JAXWS spec version. Defaults to 2.2, Accepted values are 2.0, 2.1 and 2.2
If you are using jdk wsimport tool, then just add the -target argument like below.
wsimport -keep -d \myDirToStoreExtractedClientCode -target 2.1 \myWSDLlocation\mineNotYours.wsdl
(Thanks Paul Vargas for helping out, old post but still helpful.)