Webservice客户端工程导成runnable jar包运行时出现异常

在eclipse中使用spring 4.1.3.RELEASE和cxf 2.5.0开发的Webservice客户端,导出为runnable jar包后运行出现NullPointerException。问题源于打包方式,特别是'Extract required libraries into generated JAR'选项。解决方案是选择'Package required libraries into generated JAR'或'Copy required libraries into a sub-folder next to the generated JAR'。异常源于cxf框架的多个jar包中的bus-extensions.txt文件冲突。
摘要由CSDN通过智能技术生成

一、问题描述
eclipse集成环境,spring 4.1.3.RELEASE + cxf 2.5.0框架,开发的Webservice客户端程序。在eclipse开发环境下运行正常,导出runnable jar包时出现如下异常:
java.lang.NullPointerException: null
at org.apache.cxf.wsdl11.WSDLServiceFactory.(WSDLServiceFactory.java:92)
at org.apache.cxf.jaxws.ServiceImpl.initializePorts(ServiceImpl.java:204)
at org.apache.cxf.jaxws.ServiceImpl.(ServiceImpl.java:148)
at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:90)
at javax.xml.ws.Service.(Unknown Source) ~[na:1.7.0_79]

二、初步分析
既然代码工程在eclipse能够正常运行,导出包后出现空指针异常,应该是打包的问题,runnable jar打包对依赖库的处理方式有三种,如下图所示:
这里写图片描述
Library handing的三种处理方式解释如下:
1、Extract required libraries into generated JAR。
把项目中所有的依赖jar包内的class,xml等文件都拆开,放在jar的对应的目录中,即导出的jar文件是一个独立的,没有其

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
中文乱码通常是由于字符编码不一致导致的。解决方法如下: 1. 在客户端中设置字符编码为UTF-8(或与服务端相同的编码),例如: ```java String encoding = "UTF-8"; BindingProvider provider = (BindingProvider) port; Map<String, Object> requestContext = provider.getRequestContext(); requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint); requestContext.put(BindingProvider.USERNAME_PROPERTY, username); requestContext.put(BindingProvider.PASSWORD_PROPERTY, password); requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true); requestContext.put(MessageContext.HTTP_REQUEST_HEADERS, headers); requestContext.put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 8192); requestContext.put(BindingProviderProperties.CONNECT_TIMEOUT, 3000); requestContext.put(BindingProviderProperties.REQUEST_TIMEOUT, 3000); requestContext.put(JAXWSProperties.HTTP_RESPONSE_TIMEOUT, 3000); requestContext.put(JAXWSProperties.HTTP_CLIENT_ALLOW_CHUNKING, true); requestContext.put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 8192); requestContext.put(JAXWSProperties.CONNECT_TIMEOUT, 3000); requestContext.put(JAXWSProperties.REQUEST_TIMEOUT, 3000); requestContext.put(JAXWSProperties.HTTP_RESPONSE_TIMEOUT, 3000); requestContext.put(JAXWSProperties.HTTP_CLIENT_ALLOW_CHUNKING, true); requestContext.put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 8192); requestContext.put(BindingProviderProperties.CONNECT_TIMEOUT, 3000); requestContext.put(BindingProviderProperties.REQUEST_TIMEOUT, 3000); requestContext.put(JAXWSProperties.HTTP_RESPONSE_TIMEOUT, 3000); requestContext.put(JAXWSProperties.HTTP_CLIENT_ALLOW_CHUNKING, true); requestContext.put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 8192); //设置字符编码 requestContext.put(BindingProviderProperties.ENCODING, encoding); ``` 2. 在服务端中设置字符编码为UTF-8(或与客户端相同的编码),例如: ```xml <?xml version="1.0" encoding="UTF-8"?> <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://localhost:8080/HelloWorld" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://localhost:8080/HelloWorld"> <types> <xsd:schema> <xsd:import namespace="http://localhost:8080/HelloWorld" schemaLocation="http://localhost:8080/HelloWorld?xsd=1"/> </xsd:schema> </types> <message name="sayHello"> <part name="name" type="xsd:string"/> </message> <message name="sayHelloResponse"> <part name="return" type="xsd:string"/> </message> <portType name="HelloWorld"> <operation name="sayHello"> <input message="tns:sayHello"/> <output message="tns:sayHelloResponse"/> </operation> </portType> <binding name="HelloWorldSoapBinding" type="tns:HelloWorld"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="sayHello"> <soap:operation soapAction=""/> <input> <soap:body use="literal"/> </input> <output> <soap:body use="literal"/> </output> </operation> </binding> <service name="HelloWorldService"> <port name="HelloWorldPort" binding="tns:HelloWorldSoapBinding"> <soap:address location="http://localhost:8080/HelloWorld"/> </port> </service> </definitions> ``` 在这个例子中,我们在WSDL文件头部设置了编码为UTF-8,并在SOAP消息的body元素中使用了use="literal"来指定使用XML文本格式。这样可以确保服务端和客户端使用相同的字符编码,避免中文乱码问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值