WebService根据WSDL生成Java代码

前提

  1. Windows 环境
  2. WSDL地址 http://127.0.0.1:8080/webservice?wsdl
  3. 新建 jaxp.properties 文件,放在 %JAVA_HOME%\jre\lib 目录下
  4. 新建 temp.xjb 文件,放哪里都行
  5. 命令 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

操作

注意
  1. WSDL地址这里只是做个示例
  2. %JAVA_HOME%\jre\lib 目录就是 Java 的安装目录下的 jre\lib目录
  3. wsimport 为 Java 自带命令,可在 %JAVA_HOME%\bin 下查看
  4. 命令语句中 C:\Users\zhe\Desktop\temp 为生成代码的存放目录
  5. 命令语句中 com.zhe.webservice 为生成代码的包路径
  6. 命令语句中 C:\Users\zhe\Desktop\temp.xjb 为前提4 temp.xjb文件
  7. 命令语句中 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

posted @   zhe_zhangheng  阅读(150)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示