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 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了