1、wsdl2java命令
wsdl2java -encoding utf-8 -d F:\IdeaProjects\dream-webservice\wsdl2javatest http://localhost:8080/server/web-publish?wsdl
其中,wsdl地址可填写url,也可填本地文件名。
2、maven插件:cxf-codegen-plugin
配置如下:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.7.3</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.build.directory}/generated-code/mywebservice</sourceRoot>
<encoding>UTF-8</encoding>
<wsdlOptions>
<wsdlOption>
<wsdl>https://10.33.29.120:18010/?wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
其中,sourceRoot标签表示client端代码输出路径,wsdl标签表示wsdl文件所在位置,可填url,也可填本地文件名字。该maven插件绑定了generate-sources这个生命段落,因此,执行generate-sources可自动生成本地stub代码。
参考:https://www.imooc.com/article/14635
注意:如果wsdl是https的格式,wsdl只能使用本地文件,否则会报错。如果非要使用https格式的url,可以用wsdl2java命令配合keytools命令来生成client端代码,具体参考以下链接
https://ssagara.blogspot.com/2012/05/code-generation-and-wsdl-exposed-over.html
https://blog.csdn.net/shfqbluestone/article/details/21242323
https://stackoverflow.com/questions/22552824/how-to-generate-client-code-using-wsdl2java-through-https?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa