进入CXF bin目录下:
->wsdl2java -p 包路径名 -d 目标文件夹 wsdl的URL地址
注:最好别指定-p,即包路径名,这样就会根据wsdl文件中的targetNamespace逆序自动生成包路径名
或者将CXF bin的路径配置到系统环境变量中,这样在任何路径下都可以调用wsdl2java命令了
还可以使用命令:
-->wsdl2java addNumbers.wsdl,前提是当前路径为addNumbers.wsdl所在路径
将wsdl文件同级目录下生成的客户端测试代码和wsdl文件都copy到工程中,编译时异常出现了。继承Service的类构造器有error,不能被正常编译。
这是三个报错的构造函数(请认真看注释描述):
//This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2
//API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1
//compliant code instead.
public IcpBusinessService(WebServiceFeature ... features) {
super(WSDL_LOCATION, SERVICE, features);
}
//This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2
//API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1
//compliant code instead.
public IcpBusinessService(URL wsdlLocation, WebServiceFeature ... features) {
super(wsdlLocation, SERVICE, features);
}
//This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2
//API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1
//compliant code instead.
public IcpBusinessService(URL wsdlLocation, QName serviceName, WebServiceFeature ... features) {
super(wsdlLocation, serviceName, features);
}
原因请参见:http://cxf.apache.org/docs/23-migration-guide.html 官方说明。
怎么解决呢? 经过研究发现,其不能正常编译通过是由于jax-ws2.2规约与java6冲突。 但程序又不能仅以java5来编译,故需要降低jax-ws规约版本,可以这样处理: 执行命令
其实代码注释中已经告诉我们解决的方法了。及使用
wsdl2java -frontend jaxws21 addNumbers.wsdl
命令。
OK问题解决。