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  阅读(149)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示