WebService根据WSDL生成Java代码
前提
-
Windows 环境
-
WSDL地址 http://127.0.0.1:8080/webservice?wsdl
-
新建 jaxp.properties 文件,放在 %JAVA_HOME%\jre\lib 目录下
-
新建 temp.xjb 文件,放哪里都行
-
命令 wsimport -encoding utf-8 -s C:\Users\zhe\Desktop\temp -p com.zhe.webservice -b http://www.w3.org/2001/XMLSchema.xsd -b C:\Users\zhe\Desktop\temp.xjb http://127.0.0.1:8080/webservice?wsdl
操作
注意
-
WSDL地址这里只是做个示例
-
%JAVA_HOME%\jre\lib 目录就是 Java 的安装目录下的 jre\lib目录
-
wsimport 为 Java 自带命令,可在 %JAVA_HOME%\bin 下查看
-
命令语句中 C:\Users\zhe\Desktop\temp 为生成代码的存放目录
-
命令语句中 com.zhe.webservice 为生成代码的包路径
-
命令语句中 C:\Users\zhe\Desktop\temp.xjb 为前提4 temp.xjb文件
-
命令语句中 http://127.0.0.1:8080/webservice?wsdl 为WSDL地址,若有需要改动 WSDL 模板,可保存 WSDL 页面生成 xml 文件到本地做修改,然后该 WSDL 地址可改为本地 xml 文件地址
文件内容
jaxp.properties 文件
点击查看代码
javax.xml.accessExternalSchema=all
javax.xml.accessExternalDTD=all
temp.xjb
点击查看代码
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
version="2.0">
<globalBindings>
<xjc:simple />
</globalBindings>
<bindings scd="~xsd:complexType">
<class name="ComplexTypeType"/>
</bindings>
<bindings scd="~xsd:simpleType">
<class name="SimpleTypeType"/>
</bindings>
<bindings scd="~xsd:group">
<class name="GroupType"/>
</bindings>
<bindings scd="~xsd:attributeGroup">
<class name="AttributeGroupType"/>
</bindings>
<bindings scd="~xsd:element">
<class name="ElementType"/>
</bindings>
<bindings scd="~xsd:attribute">
<class name="attributeType"/>
</bindings>
</bindings>
原文地址: https://www.cnblogs.com/zhe-zhangheng/articles/16014648.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通