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

时间:2017-01-31 12:45:48

标签: java noclassdeffounderror classnotfoundexception

有谁知道如何解决这个问题? 我创建了一个客户端来使用Web服务。客户端代码是:

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();
  }
 }

问题是当运行程序并获得以下错误时,anc甚至无法创建" 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

这个类和其他类是通过wsmport从wsdl文件创建的,但是我不认为这与我得到的错误有关。 org.apache.cxf.jaxws.spi.ProviderImpl类在cxf-rt-frontend-jaxws-3.1.1.jar文件中添加为项目的引用。

This is the project structure

These are the libraries

我有什么遗漏的吗?提前谢谢。

2 个答案:

答案 0 :(得分:0)

Invoker是CXF API的一部分。看起来缺少cxf-api。

如果您使用maven,请添加依赖项:

<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-api</artifactId>
    <version>YOUR_VERSION</version>
</dependency>

否则将jar添加到类路径中。

答案 1 :(得分:0)

添加您在https://mvnrepository.com/artifact/org.apache.cxf/cxf-rt-frontend-jaxws/3.1.1

找到的编译依赖项

更好,切换到Maven。