简体   繁体   English

如何使用Apache CXF作为客户端?

[英]How to use Apache CXF as client?

I know how to generate client stubs using Apache CXF. 我知道如何使用Apache CXF生成客户端存根。 However, when I try to run the generated classes, it uses JAXWS. 但是,当我尝试运行生成的类时,它使用JAXWS。 Also, I notice that the import classes of the generated classes are from the javax package. 另外,我注意到生成的类的导入类来自javax包。 How can I use set the generated classes to use the Apache CXF libraries instead of the JAXWS libraries? 如何使用set生成的类来使用Apache CXF库而不是JAXWS库?

Below is the code I use to generate the client stubs: 以下是我用于生成客户端存根的代码:

wsdl2java -frontend jaxws21 -wsdlLocation "META-INF/wsdl/WSCustom.wsdl" -client -d C:\Workspace\WSClient\META-INF\wsdl\ "C:\Workspace\WSClient\META-INF\wsdl\WSCustom.wsdl"

The stubs are correct, there shouldn't be any CXF-specific imports in them because all the information CXF needs can be represented using the JAX-WS standard annotations. 存根是正确的,它们中不应包含任何特定于CXF的导入,因为可以使用JAX-WS标准注释来表示CXF所需的所有信息。 At runtime the CXF client libraries will be used if they are on the class path, or the RI ones built in to the JDK will be used if CXF is not available. 在运行时,如果CXF客户端库位于类路径上,则将使用它们;如果CXF不可用,则将使用内置于JDK的RI库。 The generated stubs will work with either. 生成的存根都可以使用。

You asked in the comments about which CXF JARs are required if you're just running a client - as far as I know it's just cxf-rt-frontend-jaxws and cxf-rt-transports-http plus their transitive dependencies. 您在注释中询问是否仅在运行客户端需要哪些CXF JAR-据我所知,这只是cxf-rt-frontend-jaxwscxf-rt-transports-http及其传递依赖项。 If your project is built with maven then just declare those two dependencies and everything else should come in automatically, if not then download the Apache Ivy main JAR and then run 如果您的项目是使用maven构建的,则只需声明这两个依赖关系,其他所有内容都应自动输入,否则请下载Apache Ivy主JAR ,然后运行

java -jar ivy-2.3.0.jar -dependency org.apache.cxf cxf-rt-frontend-jaxws 2.7.3 -retrieve "[artifact]-[revision](-[classifier]).jar"
java -jar ivy-2.3.0.jar -dependency org.apache.cxf cxf-rt-transports-http 2.7.3 -retrieve "[artifact]-[revision](-[classifier]).jar"

This should resolve the transitive dependencies and download the relevant JARs from Maven Central into the current directory. 这应该解决传递依赖关系,并将相关的JAR从Maven Central下载到当前目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM