Apache CXF客户端在Eclipse中加载正常,但独立的jar在WSDLServiceFactory中抛出NullpointerException

我的目标是使用mvn assembly创建一个在独立jar中运行的Web服务客户端,其中包含所有依赖项:single

我使用CXF codegen wsdl2java生成了客户端,创建了名为NetBanxAutostatementService的@WebServiceClient

对于我有的依赖

2.5.2    org.apache.cxf cxf-rt-frontend-jaxws ${cxf.version} runtime   org.apache.cxf cxf-rt-transports-http ${cxf.version} runtime  

我甚至试图添加更多“东西”

   org.apache.cxf cxf-rt-core 2.5.2 runtime   org.apache.cxf cxf 2.5.2 pom runtime  

问题:每次我尝试运行“java -jar target / Netbanx-0.0.1-SNAPSHOT-jar-with-dependencies.jar”

 INFO [main] (Netbanx.java:97) - autostatement_wsdlLocation:https://www.test.netbanx.com/cgi-bin/autostatement_wsdl Exception in thread "main" java.lang.NullPointerException 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:91) at javax.xml.ws.Service.(Service.java:56) at com.netbanx.autostatement.NetBanxAutostatementService. (NetBanxAutostatementService.java:39) at my.project.netbanx.Netbanx.(Netbanx.java:98) at my.project.netbanx.Netbanx.main(Netbanx.java:130) 

这发生在调用WebServiceClient autostatementService = new NetBanxAutostatementService(autostatement_wsdlLocation)的行中; 我在日志行中知道我没有将autostatement_wsdlLocation传递为null

Java代码:

 URL autostatement_wsdlLocation = null; URL payment_wsdlLocation = null; try { autostatement_wsdlLocation = new URL(properties.getProperty("autostatement_wsdlLocation")); payment_wsdlLocation = new URL(properties.getProperty("payment_wsdlLocation")); } catch (MalformedURLException e) { logger.error("MalformedURLException",e); } /** * Load the Netbanx's webservices AutostatementService and PaymentService */ try { logger.info("autostatement_wsdlLocation:"+autostatement_wsdlLocation.toString()); autostatementService = new NetBanxAutostatementService(autostatement_wsdlLocation); //it is here I get the NullPointerException error logger.info("payment_wsdlLocation:"+payment_wsdlLocation.toString()); paymentService = new NetBanxPaymentService(payment_wsdlLocation); webServiceStarted = true; } catch(javax.xml.ws.WebServiceException wsException ){ String error = "Cannot create NetBanx web service please make sure this host can reach:" + autostatement_wsdlLocation +" and " + payment_wsdlLocation; logger.error(error); logger.error("WebServiceException",wsException); 

}

最有可能的是你如何创建你的单jar。 正常使用程序集插件不允许这样,因为需要将CXF的各种部分META-INF / *东西合并在一起。 这将包括所有的/ META-INF / spring *以及/ META-INF / cxf / *中的大部分内容我建议使用shade插件。 有关示例,请参阅CXF的bundle jar的pom.xml。

http://svn.apache.org/repos/asf/cxf/trunk/osgi/bundle/all/

扩展@ DanielKulp的答案,这对我来说对CXF 2.7.7起作用(以防链接死机)。 使用以下附加变换器配置您的阴影插件:

     META-INF/spring.handlers   META-INF/services/com.sun.tools.xjc.Plugin   META-INF/spring.schemas   META-INF/cxf/cxf.extension   META-INF/extensions.xml   META-INF/cxf/extensions.xml   META-INF/cxf/bus-extensions.txt   META-INF/cxf/bus-extensions.xml   META-INF/wsdl.plugin.xml   META-INF/tools.service.validator.xml   META-INF/cxf/java2wsbeans.xml    

您应该尝试使用一个jar插件,它让您创建干净且完全独立的超级jar子

http://code.google.com/p/onejar-maven-plugin/

作为对@Matt R的回答的补充,我用这段代码用maven-assembly-plugin替换了POM部分:

  org.apache.maven.plugins maven-jar-plugin 2.3.2    true com.xxx.App      org.apache.maven.plugins maven-shade-plugin 3.0.0   package  shade      META-INF/spring.handlers   META-INF/services/com.sun.tools.xjc.Plugin   META-INF/spring.schemas   META-INF/cxf/cxf.extension   META-INF/extensions.xml   META-INF/cxf/extensions.xml   META-INF/cxf/bus-extensions.txt   META-INF/cxf/bus-extensions.xml   META-INF/wsdl.plugin.xml   META-INF/tools.service.validator.xml   META-INF/cxf/java2wsbeans.xml     *:*  META-INF/*.SF META-INF/*.DSA META-INF/*.RSA        

排除部分是为了防止出现Java安全问题。