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

3

5

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
Artificiality answered 29/5, 2013 at 13:20 Comment(0)
E
11

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.

Earache answered 29/5, 2013 at 16:13 Comment(0)
P
2

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

Paillasse answered 15/7, 2013 at 10:5 Comment(0)
R
1

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

Romanist answered 23/8, 2018 at 15:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.