JDK 21构建时wsimport失败及XMLBeans编译问题求助
问题排查与解决方案
一、jaxws-maven-plugin 解析<bindings>错误
这个问题本质是JDK版本升级后,老版本插件与JDK17+的模块系统不兼容,或是绑定文件配置有误,具体解决步骤:
- 升级jaxws-maven-plugin到兼容版本
JDK9+移除了内置的JAX-WS模块,必须使用外部的JAX-WS实现,建议升级到3.0.0+版本:
<plugin> <groupId>com.sun.xml.ws</groupId> <artifactId>jaxws-maven-plugin</artifactId> <version>3.0.2</version> <executions> <execution> <goals> <goal>wsimport</goal> </goals> <configuration> <wsdlFiles> <wsdlFile>src/main/resources/test.wsdl</wsdlFile> </wsdlFiles> <bindings> <binding> <bindingFile>src/main/resources/jaxws-bindings.xml</bindingFile> </binding> </bindings> </configuration> </execution> </executions> <dependencies> <dependency> <groupId>com.sun.xml.ws</groupId> <artifactId>jaxws-rt</artifactId> <version>3.0.2</version> </dependency> </dependencies> </plugin>
- 校验绑定文件的命名空间
确保绑定文件根元素的xmlns指向正确的JAX-WS绑定命名空间,错误的命名空间会导致解析失败:
<bindings xmlns="http://java.sun.com/xml/ns/jaxws/bindings" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" version="2.0"> <!-- 你的绑定规则 --> </bindings>
- 确认绑定文件路径正确性
检查插件配置中<bindingFile>的路径是否基于项目根目录,必要时用绝对路径测试,排除路径引用错误。
二、xmlbeans-maven-plugin 处理Schema失败
这个问题通常是插件版本兼容问题、WSDL/Schema路径错误或XML语法不规范导致,解决步骤:
- 升级xmlbeans-maven-plugin到兼容JDK17的版本
老版本插件不支持JDK17的模块系统,建议升级到3.1.0及以上:
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>xmlbeans-maven-plugin</artifactId> <version>3.1.0</version> <executions> <execution> <goals> <goal>xmlbeans</goal> </goals> <configuration> <schemaDirectory>src/main/resources</schemaDirectory> <includeSchemas> <includeSchema>test.wsdl</includeSchema> </includeSchemas> <!-- 匹配文件编码,避免解析乱码 --> <encoding>UTF-8</encoding> </configuration> </execution> </executions> <dependencies> <dependency> <groupId>org.apache.xmlbeans</groupId> <artifactId>xmlbeans</artifactId> <version>5.1.1</version> </dependency> </dependencies> </plugin>
- 检查WSDL中Schema的引用路径
打开test.wsdl,确认其中<xs:import>或<xs:include>指向的Schema文件存在,路径正确。如果Schema不在默认搜索路径,可在插件配置中添加<schemaSearchPath>指定搜索目录:
<configuration> <!-- 其他配置 --> <schemaSearchPath>src/main/resources/schemas</schemaSearchPath> </configuration>
验证WSDL与Schema的语法有效性
JDK17的XML解析器对语法错误更严格,用XML验证工具(如xmllint)检查WSDL和Schema是否存在未闭合标签、无效命名空间等问题。补充缺失的XML依赖
JDK17移除了javax.xml.bind等模块,需显式引入相关依赖:
<dependencies> <dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> <version>2.3.1</version> </dependency> <dependency> <groupId>org.glassfish.jaxb</groupId> <artifactId>jaxb-runtime</artifactId> <version>2.3.1</version> </dependency> </dependencies>
通用排查技巧
- 清理Maven缓存并强制更新依赖:执行
mvn clean install -U - 查看详细错误日志:执行
mvn -X xmlbeans:xmlbeans,定位具体错误行 - 明确指定JDK版本:在pom.xml中配置maven-compiler-plugin的source/target为17或21:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.11.0</version> <configuration> <source>17</source> <target>17</target> <encoding>UTF-8</encoding> </configuration> </plugin>
内容的提问来源于stack exchange,提问作者noobboi
相关产品推荐
相关产品推荐

