Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

constructor Service in class javax.xml.ws.Service cannot be applied to given types

Tags:

service

jax-ws

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
like image 384
user2432573 Avatar asked May 29 '13 13:05

user2432573


3 Answers

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):

  1. Use Java SE 7 or Java EE 6.

  2. Re-run wsdl2java with argument -frontend jaxws21 to generate JAX-WS 2.1 compliant code instead.

  3. Change the classloader for load first the classes included in the application.

like image 145
Paul Vargas Avatar answered Nov 09 '22 08:11

Paul Vargas


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).

like image 33
Remlap21 Avatar answered Nov 09 '22 09:11

Remlap21


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.)

like image 1
Jose Peralez Avatar answered Nov 09 '22 08:11

Jose Peralez