我从 java 8 迁移到 java 17 在 java 8 中我使用这个插件从 xsd 生成 xml:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.2</version> (I tried to update to 0.15.2)
<executions>
<execution>
<id>add-source</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources/META-INF/xsd</schemaDirectory>
<schemaIncludes>
<include>fe2_flux_generique.xsd</include>
</schemaIncludes>
<bindingDirectory>src/main/resources/META-INF/xsd</bindingDirectory>
<bindingIncludes>
<include>fe2_flux_generique.xjb</include>
</bindingIncludes>
<generateDirectory>${project.basedir}/src/generated</generateDirectory>
<generatePackage>fr.icdc.dei.ddr.fe2.xml.domain</generatePackage>
<!-- Other configuration options -->
</configuration>
</execution>
</executions>
</plugin>
xsd 文件:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:ddr:fe2:flux:1.0"
xmlns:flux="urn:ddr:fe2:flux:1.0" elementFormDefault="qualified"
version="1.0.0">
*********************
***************
*******
</xsd:schema>
xjb 文件:
<?xml version="1.0" encoding="UTF-8"?>
<jxb:bindings version="1.0"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<jxb:globalBindings>
<jxb:serializable uid="1" />
<!-- date time adapter -->
<jxb:javaType name="java.util.Calendar"
xmlType="xsd:dateTime"
parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime"
printMethod="javax.xml.bind.DatatypeConverter.printDateTime" />
</jxb:globalBindings>
</jxb:bindings>
在java 17中,构建成功终止,但没有生成文件,我尝试添加jkarta依赖项,并在xsd和xjb文件中更改xmlns:jxb =“http://java.sun.com/xml/ns/jaxb” ” 到 xmlns:jxb="https://jakarta.ee/xml/ns/jaxb" jxb:version="3.0" 但不起作用
一旦我也使用了这个插件。确切地说,我不知道为什么,但我也遇到了这个插件的问题,从那时起我更喜欢 org.codehaus.mojo:jaxb2-maven-plugin。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<sources>
<source>src/main/schema</source>
</sources>
<xjbSources>
<xjbSource>src/main/xjb</xjbSource>
</xjbSources>
</configuration>
</execution>
</executions>
</plugin>
<jxb:bindings schemaLocation="../schema/fe2_flux_generique.xsd">
<jxb:schemaBindings>
<jxb:package name="fr.icdc.dei.ddr.fe2.xml.domain"/>
</jxb:schemaBindings>
</jxb:bindings>