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:
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
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
:
javax.xml.ws.Service.Service(URL, QName)
For Java SE 7 or Java EE 6, JAX-WS API 2.2. The constructors in javax.xml.ws.Service
:
javax.xml.ws.Service.Service(URL, QName)
javax.xml.ws.Service.Service(URL, QName, WebServiceFeature...) // You need this!
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.
If using Maven to build you should add this to the execution configuration
<defaultOptions>
<extraargs>
<extraarg>-frontend</extraarg>
<extraarg>jaxws21</extraarg>
</extraargs>
</defaultOptions>
(thanks to Paul Vargas for pointing me in the right direction).
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With