Search code examples
javanoclassdeffounderrorclassnotfoundexception

java.lang.NoClassDefFoundError: org/apache/cxf/service/invoker/Invoker


Does anyone know how to fix this? I created a client to consume a webservice. The client code is:

package cliente;

import java.util.List;

import handler.HeaderHandler;
import webservice.BoletinOficial;
import webservice.BoletinOficialService;
import petanuncio.PeticionAnuncio;
import respanuncio.RespuestaAnuncio;

import org.apache.cxf.jaxws.binding.DefaultBindingImpl;

import javax.xml.ws.BindingProvider;
import javax.xml.ws.handler.Handler;
import java.util.ArrayList;


public class Cliente {

/**
 * Main
 * @param args
 */
 @SuppressWarnings("rawtypes")
public static void main(String[] args) {

  String endpointURL = "";
  try {


       BoletinOficialService service = new BoletinOficialService();

       BoletinOficial proxy = service.getBoletinOficialSoap11();


//rest of code

  } catch (Exception e) {
   e.printStackTrace();
  }
 }

The problem is when running the program and get the following error anc cannot even create "service":

 Exception in thread "main" java.util.ServiceConfigurationError: javax.xml.ws.spi.Provider: Provider org.apache.cxf.jaxws.spi.ProviderImpl could not be instantiated
    at java.util.ServiceLoader.fail(Unknown Source)
    at java.util.ServiceLoader.access$100(Unknown Source)
    at java.util.ServiceLoader$LazyIterator.nextService(Unknown Source)
    at java.util.ServiceLoader$LazyIterator.next(Unknown Source)
    at java.util.ServiceLoader$1.next(Unknown Source)
    at javax.xml.ws.spi.Provider.getProviderUsingServiceLoader(Unknown Source)
    at javax.xml.ws.spi.Provider.provider(Unknown Source)
    at javax.xml.ws.Service.<init>(Unknown Source)
    at webservice.BoletinOficialService.<init>(BoletinOficialService.java:46)
    at cliente.Cliente.main(Cliente.java:35)
Caused by: java.lang.NoClassDefFoundError: org/apache/cxf/service/invoker/Invoker
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
    at java.lang.Class.getConstructor0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    ... 8 more
Caused by: java.lang.ClassNotFoundException: org.apache.cxf.service.invoker.Invoker
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 12 more

This class and others were created via wsimport from a wsdl file, althoug I don't think this is related to the error I am getting. The class org.apache.cxf.jaxws.spi.ProviderImpl is in cxf-rt-frontend-jaxws-3.1.1.jar file whis is added as referece to the project.

This is the project structure

These are the libraries

Is there anything I am missing? Thank you in advance.


Solution

  • Add the compile dependencies you find at https://mvnrepository.com/artifact/org.apache.cxf/cxf-rt-frontend-jaxws/3.1.1

    Better, switch to Maven.