Maven JAXB2 插件无法处理绑定文件
Maven JAXB2 plugin fails to process bindings file
如何让它识别bingings文件然后从wsdl生成java类?
pom
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.14.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<generatePackage>com.example.demo.schema.gbg</generatePackage>
<generateDirectory>${project.basedir}/src/main/java</generateDirectory>
<schemaDirectory>${project.basedir}/src/main/resources/wsdl</schemaDirectory>
<schemaIncludes>
<include>*.wsdl</include>
</schemaIncludes>
<bindingDirectory>${project.basedir}/src/main/resources/bindings/</bindingDirectory>
<bindingIncludes>*.xml</bindingIncludes>
</configuration>
</plugin>
</plugins>
</build>
jaxb-bindings.xml
<?xml version="1.0" encoding="UTF-8" ?>
<jaxws:bindings
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- Name the package consistently (don't use wsdl URI domain name) -->
<jaxws:package name="com.id3global"/>
<!-- Use 'wrapper style rules' to produce Java names - no I don't know what it means either -->
<jaxws:enableWrapperStyle>true</jaxws:enableWrapperStyle>
<!-- Disable generation of asynchronous send/receive methods - might be fun for later though :) -->
<jaxws:enableAsyncMapping>false</jaxws:enableAsyncMapping>
<!-- Do not generate Element properties - they collide with the type namespace in Java,
and yes, *all* this boilerplate is required for wsimport to apply the setting correctly -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" elementFormDefault="qualified"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
attributeFormDefault="unqualified" jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.1">
<xs:annotation>
<xs:appinfo>
<jaxb:globalBindings generateElementProperty="false">
<xjc:serializable/>
</jaxb:globalBindings>
</xs:appinfo>
</xs:annotation>
</xs:schema>
</jaxws:bindings>
控制台:
org.xml.sax.SAXParseException; not an external binding file.
The root element must be {http://java.sun.com/xml/ns/jaxb}bindings but it is {http://java.sun.com/xml/ns/jaxws}bindings
您是否缺少 jaxb 命名空间声明?添加 jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb
如下例所示。
您还可以将 JAXWS 元素移动到 JAXB 元素中。有点像。
<?xml version="1.0"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.1" jaxb:extensionBindingPrefixes="xjc annox">
<jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
</jaxws:bindings>
</jaxb:bindings>
如何让它识别bingings文件然后从wsdl生成java类?
pom
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.14.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<generatePackage>com.example.demo.schema.gbg</generatePackage>
<generateDirectory>${project.basedir}/src/main/java</generateDirectory>
<schemaDirectory>${project.basedir}/src/main/resources/wsdl</schemaDirectory>
<schemaIncludes>
<include>*.wsdl</include>
</schemaIncludes>
<bindingDirectory>${project.basedir}/src/main/resources/bindings/</bindingDirectory>
<bindingIncludes>*.xml</bindingIncludes>
</configuration>
</plugin>
</plugins>
</build>
jaxb-bindings.xml
<?xml version="1.0" encoding="UTF-8" ?>
<jaxws:bindings
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- Name the package consistently (don't use wsdl URI domain name) -->
<jaxws:package name="com.id3global"/>
<!-- Use 'wrapper style rules' to produce Java names - no I don't know what it means either -->
<jaxws:enableWrapperStyle>true</jaxws:enableWrapperStyle>
<!-- Disable generation of asynchronous send/receive methods - might be fun for later though :) -->
<jaxws:enableAsyncMapping>false</jaxws:enableAsyncMapping>
<!-- Do not generate Element properties - they collide with the type namespace in Java,
and yes, *all* this boilerplate is required for wsimport to apply the setting correctly -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" elementFormDefault="qualified"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
attributeFormDefault="unqualified" jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.1">
<xs:annotation>
<xs:appinfo>
<jaxb:globalBindings generateElementProperty="false">
<xjc:serializable/>
</jaxb:globalBindings>
</xs:appinfo>
</xs:annotation>
</xs:schema>
</jaxws:bindings>
控制台:
org.xml.sax.SAXParseException; not an external binding file.
The root element must be {http://java.sun.com/xml/ns/jaxb}bindings but it is {http://java.sun.com/xml/ns/jaxws}bindings
您是否缺少 jaxb 命名空间声明?添加 jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb
如下例所示。
您还可以将 JAXWS 元素移动到 JAXB 元素中。有点像。
<?xml version="1.0"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.1" jaxb:extensionBindingPrefixes="xjc annox">
<jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
</jaxws:bindings>
</jaxb:bindings>