Sure, here’s the translation: jaxb2-maven-plugin 与 Jakarta 和 Java 11

huangapple go评论72阅读模式
英文:

jaxb2-maven-plugin Jakarta and java 11

问题

package org.ttt.raw.reporting.core.fussnote;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlType;

/**
 * Java-Klasse für FussnoteType complex type.
 *
 * Das folgende Schemafragment gibt den erwarteten Content an, der in dieser Klasse enthalten ist.
 *
 * <complexType name="FussnoteType">
 * <complexContent>
 *
 * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
 *
 *   &lt;sequence&gt;
 *
 *     &lt;element name="FussnoteNummer" type="{http://www.w3.org/2001/XMLSchema}string"/&gt;
 *
 *     &lt;element name="FussnoteText" type="{http://www.w3.org/2001/XMLSchema}string"/&gt;
 *
 *   &lt;/sequence&gt;
 *
 * &lt;/restriction&gt;
 * </complexContent>
 * </complexType>
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "FussnoteType", propOrder = {
    "fussnoteNummer",
    "fussnoteText"
})
public class FussnoteType {

    @XmlElement(name = "FussnoteNummer", required = true)
    protected String fussnoteNummer;
    @XmlElement(name = "FussnoteText", required = true)
    protected String fussnoteText;

    /**
     * Ruft den Wert der fussnoteNummer-Eigenschaft ab.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getFussnoteNummer() {
        return fussnoteNummer;
    }

    /**
     * Legt den Wert der fussnoteNummer-Eigenschaft fest.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setFussnoteNummer(String value) {
        this.fussnoteNummer = value;
    }

    /**
     * Ruft den Wert der fussnoteText-Eigenschaft ab.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getFussnoteText() {
        return fussnoteText;
    }

    /**
     * Legt den Wert der fussnoteText-Eigenschaft fest.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setFussnoteText(String value) {
        this.fussnoteText = value;
    }
}
<dependencies>
    <!-- Other dependencies -->

    <!-- API, java.xml.bind module -->
    <dependency>
        <groupId>jakarta.xml.bind</groupId>
        <artifactId>jakarta.xml.bind-api</artifactId>
        <version>3.0.0-RC3</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <!-- Other plugins -->

        <!-- JAXB2 Maven Plugin -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxb2-maven-plugin</artifactId>
            <version>2.5.0</version>
            <executions>
                <execution>
                    <id>xjc</id>
                    <goals>
                        <goal>xjc</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <sources>
                    <source>src/main/resources/reports/core/fussnote/xsd/fussnote.xsd</source>
                </sources>
                <packageName>org.ttt.raw.reporting.core.fussnote</packageName>
                <outputDirectory>target/generated-sources</outputDirectory>
                <clearOutputDir>false</clearOutputDir>
                <xsdPathWithinArtifact>.</xsdPathWithinArtifact>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>jakarta.xml.bind</groupId>
                    <artifactId>jakarta.xml.bind-api</artifactId>
                    <version>3.0.0-RC3</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

Note: The provided code snippets have been translated according to your instructions. If you need any further assistance, feel free to ask.

英文:

I am trying to migrate to java 11 and jakarta. I need to create java classes from XSD Files as I did in Java EE. I have changed all jaxb imports into jakarta. But I can not make jaxb2 to create classes with jakarta namspace instead of jaxb.
If I add no dependencies to the plugin part then the class will be created with javax namspace, which I do not need and the imports can not be found anyway with Java error: package javax.xml.bind.annotation does not exist.
The generated class is:

package org.ttt.raw.reporting.core.fussnote;
import javax.xml.bind.annotation.XmlAccessType; // I need to have jakarta.xml.bind ... here!
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
Java-Klasse f&#252;r FussnoteType complex type.
Das folgende Schemafragment gibt den erwarteten Content an, der in dieser Klasse enthalten ist.
&lt;complexType name=&quot;FussnoteType&quot;&gt;
&lt;complexContent&gt;
&amp;lt;restriction base=&quot;{http://www.w3.org/2001/XMLSchema}anyType&quot;&amp;gt;
&amp;lt;sequence&amp;gt;
&amp;lt;element name=&quot;FussnoteNummer&quot; type=&quot;{http://www.w3.org/2001/XMLSchema}string&quot;/&amp;gt;
&amp;lt;element name=&quot;FussnoteText&quot; type=&quot;{http://www.w3.org/2001/XMLSchema}string&quot;/&amp;gt;
&amp;lt;/sequence&amp;gt;
&amp;lt;/restriction&amp;gt;
&lt;/complexContent&gt;
&lt;/complexType&gt;
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = &quot;FussnoteType&quot;, propOrder = {
&quot;fussnoteNummer&quot;,
&quot;fussnoteText&quot;
})
public class FussnoteType {
@XmlElement(name = &quot;FussnoteNummer&quot;, required = true)
protected String fussnoteNummer;
@XmlElement(name = &quot;FussnoteText&quot;, required = true)
protected String fussnoteText;
/**
* Ruft den Wert der fussnoteNummer-Eigenschaft ab.
* 
* @return
*     possible object is
*     {@link String }
*     
*/
public String getFussnoteNummer() {
return fussnoteNummer;
}
/**
* Legt den Wert der fussnoteNummer-Eigenschaft fest.
* 
* @param value
*     allowed object is
*     {@link String }
*     
*/
public void setFussnoteNummer(String value) {
this.fussnoteNummer = value;
}
/**
* Ruft den Wert der fussnoteText-Eigenschaft ab.
* 
* @return
*     possible object is
*     {@link String }
*     
*/
public String getFussnoteText() {
return fussnoteText;
}
/**
* Legt den Wert der fussnoteText-Eigenschaft fest.
* 
* @param value
*     allowed object is
*     {@link String }
*     
*/
public void setFussnoteText(String value) {
this.fussnoteText = value;
}
}

If I add jakarta.xml.bind then the FussnoteType class will not be generated at all an I get these errors:

[ERROR] Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:2.5.0:xjc (xjc) on project raw-reporting-core: A Plug-in could not be loaded: &quot;java.util.ServiceConfigurationError: com.sun.tools.xjc.Plugin: com.sun.tools.xjc.addon.accessors.PluginImpl Unable to get public no-arg constructor
[ERROR] at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:581)
[ERROR] at java.base/java.util.ServiceLoader.getConstructor(ServiceLoader.java:672)
[ERROR] at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1232)
[ERROR] at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1264)
[ERROR] at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1299)
[ERROR] at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1384)
[ERROR] at com.sun.tools.xjc.Options.findServices(Options.java:979)
[ERROR] at com.sun.tools.xjc.Options.getAllPlugins(Options.java:355)
[ERROR] at com.sun.tools.xjc.Options.parseArgument(Options.java:694)
[ERROR] at com.sun.tools.xjc.Driver$OptionsEx.parseArgument(Driver.java:502)
[ERROR] at com.sun.tools.xjc.Options.parseArguments(Options.java:827)
[ERROR] at com.sun.tools.xjc.Driver.run(Driver.java:231)
[ERROR] at org.codehaus.mojo.jaxb2.javageneration.AbstractJavaGeneratorMojo.performExecution(AbstractJavaGeneratorMojo.java:475)
[ERROR] at org.codehaus.mojo.jaxb2.AbstractJaxbMojo.execute(AbstractJaxbMojo.java:337)
[ERROR] at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
[ERROR] at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
[ERROR] at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
[ERROR] at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
[ERROR] at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
[ERROR] at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
[ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR] at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
[ERROR] at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
[ERROR] Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlAccessType
[ERROR] at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
[ERROR] at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3137)
[ERROR] at java.base/java.lang.Class.getConstructor0(Class.java:3342)
[ERROR] at java.base/java.lang.Class.getConstructor(Class.java:2151)
[ERROR] at java.base/java.util.ServiceLoader$1.run(ServiceLoader.java:659)
[ERROR] at java.base/java.util.ServiceLoader$1.run(ServiceLoader.java:656)
[ERROR] at java.base/java.security.AccessController.doPrivileged(Native Method)
[ERROR] at java.base/java.util.ServiceLoader.getConstructor(ServiceLoader.java:667)
[ERROR] ... 35 more
[ERROR] Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlAccessType
[ERROR] at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
[ERROR] at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
[ERROR] at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
[ERROR] at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
[ERROR] ... 43 more

The pom is:

&lt;parent&gt;
&lt;groupId&gt;org.ttt.baw.reporting&lt;/groupId&gt;
&lt;artifactId&gt;parent-baw-reporting&lt;/artifactId&gt;
&lt;version&gt;${revision}&lt;/version&gt;
&lt;relativePath&gt;../parent-baw-reporting&lt;/relativePath&gt;
&lt;/parent&gt;
&lt;artifactId&gt;baw-reporting-core&lt;/artifactId&gt;
&lt;name&gt;RAW-Reporting-Core&lt;/name&gt;
&lt;description&gt;
- Technisches Modul
- Die technische Implementierung des Reportings
- Keine Fachlichkeit!
&lt;/description&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.ttt.baw.reporting&lt;/groupId&gt;
&lt;artifactId&gt;baw-config-service&lt;/artifactId&gt;
&lt;version&gt;${project.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.ttt.baw.reporting&lt;/groupId&gt;
&lt;artifactId&gt;baw-io&lt;/artifactId&gt;
&lt;version&gt;${project.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.ttt.baw.reporting&lt;/groupId&gt;
&lt;artifactId&gt;baw-results-core&lt;/artifactId&gt;
&lt;version&gt;${project.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.ttt.swaw.pl&lt;/groupId&gt;
&lt;artifactId&gt;swaw-pl&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
&lt;artifactId&gt;commons-lang3&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;!-- API, java.xml.bind module --&gt;
&lt;dependency&gt;
&lt;groupId&gt;jakarta.xml.bind&lt;/groupId&gt;
&lt;artifactId&gt;jakarta.xml.bind-api&lt;/artifactId&gt;
&lt;version&gt;3.0.0-RC3&lt;/version&gt;
&lt;/dependency&gt;
&lt;!-- Tests --&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.google.jimfs&lt;/groupId&gt;
&lt;artifactId&gt;jimfs&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.mockito&lt;/groupId&gt;
&lt;artifactId&gt;mockito-core&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;build&gt;
&lt;plugins&gt;
&lt;!-- @see http://www.mojohaus.org/jaxb2-maven-plugin/Documentation/v2.2/example_xjc_basic.html --&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
&lt;artifactId&gt;jaxb2-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;2.5.0&lt;/version&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;id&gt;xjc&lt;/id&gt;
&lt;goals&gt;
&lt;goal&gt;xjc&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;configuration&gt;
&lt;sources&gt;
&lt;source&gt;src/main/resources/reports/core/fussnote/xsd/fussnote.xsd&lt;/source&gt;
&lt;/sources&gt;
&lt;packageName&gt;org.ttt.baw.reporting.core.fussnote&lt;/packageName&gt;
&lt;outputDirectory&gt;target/generated-sources&lt;/outputDirectory&gt;
&lt;clearOutputDir&gt;false&lt;/clearOutputDir&gt;
&lt;xsdPathWithinArtifact&gt;.&lt;/xsdPathWithinArtifact&gt;
&lt;/configuration&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;jakarta.xml.bind&lt;/groupId&gt;
&lt;artifactId&gt;jakarta.xml.bind-api&lt;/artifactId&gt;
&lt;version&gt;3.0.0-RC3&lt;/version&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;

答案1

得分: 16

经过几天的研究,我针对与同一个插件相关的问题的基线解决方案如下:

pom.xml 文件

<properties>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    
    <!-- maven compiler version -->
    <maven.compiler.version>3.8.1</maven.compiler.version>
    
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    
    <version.maven.jakartaee>9.0.0</version.maven.jakartaee>
    <version.maven.jakarta.xml.bind-api>3.0.0</version.maven.jakarta.xml.bind-api>
    <version.maven.jakarta.ws.rs-api>3.0.0</version.maven.jakarta.ws.rs-api>
    <version.maven.jakarta.activation.api>2.0.0</version.maven.jakarta.activation.api>
    <version.maven.jaxb.impl>3.0.0</version.maven.jaxb.impl>
    <version.maven.jaxb.xjc>3.0.0</version.maven.jaxb.xjc>
    <version.maven.servlet.api>5.0.0</version.maven.servlet.api>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven.compiler.version}</version>
            <configuration>
                <source>${maven.compiler.source}</source>
                <target>${maven.compiler.target}</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxb2-maven-plugin</artifactId>
            <version>2.5.0</version>
            <executions>
                <execution>
                    <id>xjc</id>
                    <goals>
                        <goal>xjc</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <xjbSources>
                    <xjbSource>src/main/resources/global.xjb</xjbSource>
                </xjbSources>
                <sources>
                    <source>src/main/resources/xsd</source>
                </sources>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.glassfish.jaxb</groupId>
                    <artifactId>jaxb-xjc</artifactId>
                    <version>${version.maven.jaxb.xjc}</version>
                </dependency>
                <!-- other dependencies -->
            </dependencies>
        </plugin>
    </plugins>
</build>

<dependencies>
    <!-- dependencies -->
</dependencies>

在 resources 文件夹中,我有一个 bindings.xjb 文件,还有一个名为 XSD 的文件夹,其中包含 XSD 模式。

global.xjb 文件

<jaxb:bindings xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb" xmlns:xsi="http://www.w3.org/2001/XMLSchema" version="3.0">

    <jaxb:globalBindings>

        <jaxb:serializable uid="1"/>

        <!-- date time adapter -->
        <jaxb:javaType name="java.util.Calendar" xmlType="xsi:dateTime"
                       parseMethod="jakarta.xml.bind.DatatypeConverter.parseDateTime"
                       printMethod="jakarta.xml.bind.DatatypeConverter.printDateTime" />

    </jaxb:globalBindings>

    <jaxb:bindings schemaLocation="xsd/schema.xsd">
        <jaxb:schemaBindings>
            <jaxb:package name="com.test.request" />
        </jaxb:schemaBindings>
    </jaxb:bindings>

</jaxb:bindings>

schema.xsd 文件

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://services.memorynotfound.com/" elementFormDefault="qualified">

    <xs:complexType name="CourseRequest">
        <xs:sequence>
            <xs:element name="id" type="xs:int" nillable="false"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="CourseResponse">
        <xs:sequence>
            <xs:element name="id" type="xs:int"/>
            <xs:element name="name" type="xs:string"/>
            <xs:element name="description" type="xs:string"/>
            <xs:element name="created" type="xs:dateTime"/>
        </xs:sequence>
    </xs:complexType>

</xs:schema>
英文:

After some days of research my baseline solution for a problem related to the same plugin is the following:

pom.xml file

&lt;properties&gt;
&lt;maven.compiler.source&gt;11&lt;/maven.compiler.source&gt;
&lt;maven.compiler.target&gt;11&lt;/maven.compiler.target&gt;
&lt;!-- maven compiler version --&gt;
&lt;maven.compiler.version&gt;3.8.1&lt;/maven.compiler.version&gt;
&lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
&lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
&lt;version.maven.jakartaee&gt;9.0.0&lt;/version.maven.jakartaee&gt;
&lt;version.maven.jakarta.xml.bind-api&gt;3.0.0&lt;/version.maven.jakarta.xml.bind-api&gt;
&lt;version.maven.jakarta.ws.rs-api&gt;3.0.0&lt;/version.maven.jakarta.ws.rs-api&gt;
&lt;version.maven.jakarta.activation.api&gt;2.0.0&lt;/version.maven.jakarta.activation.api&gt;
&lt;version.maven.jaxb.impl&gt;3.0.0&lt;/version.maven.jaxb.impl&gt;
&lt;version.maven.jaxb.xjc&gt;3.0.0&lt;/version.maven.jaxb.xjc&gt;
&lt;version.maven.servlet.api&gt;5.0.0&lt;/version.maven.servlet.api&gt;
&lt;/properties&gt;
&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
&lt;version&gt;${maven.compiler.version}&lt;/version&gt;
&lt;configuration&gt;
&lt;source&gt;${maven.compiler.source}&lt;/source&gt;
&lt;target&gt;${maven.compiler.target}&lt;/target&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
&lt;artifactId&gt;jaxb2-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;2.5.0&lt;/version&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;id&gt;xjc&lt;/id&gt;
&lt;goals&gt;
&lt;goal&gt;xjc&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;configuration&gt;
&lt;xjbSources&gt;
&lt;xjbSource&gt;src/main/resources/global.xjb&lt;/xjbSource&gt;
&lt;/xjbSources&gt;
&lt;sources&gt;
&lt;source&gt;src/main/resources/xsd&lt;/source&gt;
&lt;/sources&gt;
&lt;/configuration&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.glassfish.jaxb&lt;/groupId&gt;
&lt;artifactId&gt;jaxb-xjc&lt;/artifactId&gt;
&lt;version&gt;${version.maven.jaxb.xjc}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;jakarta.activation&lt;/groupId&gt;
&lt;artifactId&gt;jakarta.activation-api&lt;/artifactId&gt;
&lt;version&gt;${version.maven.jakarta.activation.api}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;jakarta.xml.bind&lt;/groupId&gt;
&lt;artifactId&gt;jakarta.xml.bind-api&lt;/artifactId&gt;
&lt;version&gt;${version.maven.jakarta.xml.bind-api}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.sun.xml.bind&lt;/groupId&gt;
&lt;artifactId&gt;jaxb-impl&lt;/artifactId&gt;
&lt;version&gt;${version.maven.jaxb.impl}&lt;/version&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;jakarta.xml.bind&lt;/groupId&gt;
&lt;artifactId&gt;jakarta.xml.bind-api&lt;/artifactId&gt;
&lt;version&gt;${version.maven.jakarta.xml.bind-api}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;jakarta.ws.rs&lt;/groupId&gt;
&lt;artifactId&gt;jakarta.ws.rs-api&lt;/artifactId&gt;
&lt;version&gt;${version.maven.jakarta.ws.rs-api}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;jakarta.servlet&lt;/groupId&gt;
&lt;artifactId&gt;jakarta.servlet-api&lt;/artifactId&gt;
&lt;version&gt;${version.maven.servlet.api}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;jakarta.platform&lt;/groupId&gt;
&lt;artifactId&gt;jakarta.jakartaee-api&lt;/artifactId&gt;
&lt;version&gt;${version.maven.jakartaee}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.sun.xml.bind&lt;/groupId&gt;
&lt;artifactId&gt;jaxb-impl&lt;/artifactId&gt;
&lt;version&gt;${version.maven.jaxb.impl}&lt;/version&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;

In the resources folder, I have a bindings.xjb file and another folder named XSD with the XSD schema.

global.xjb file

&lt;jaxb:bindings xmlns:jaxb=&quot;https://jakarta.ee/xml/ns/jaxb&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema&quot; version=&quot;3.0&quot;&gt;
&lt;jaxb:globalBindings&gt;
&lt;jaxb:serializable uid=&quot;1&quot;/&gt;
&lt;!-- date time adapter --&gt;
&lt;jaxb:javaType name=&quot;java.util.Calendar&quot; xmlType=&quot;xsi:dateTime&quot;
parseMethod=&quot;jakarta.xml.bind.DatatypeConverter.parseDateTime&quot;
printMethod=&quot;jakarta.xml.bind.DatatypeConverter.printDateTime&quot; /&gt;
&lt;/jaxb:globalBindings&gt;
&lt;jaxb:bindings schemaLocation=&quot;xsd/schema.xsd&quot;&gt;
&lt;jaxb:schemaBindings&gt;
&lt;jaxb:package name=&quot;com.test.request&quot; /&gt;
&lt;/jaxb:schemaBindings&gt;
&lt;/jaxb:bindings&gt;
&lt;/jaxb:bindings&gt;

schema.xsd file

&lt;xs:schema xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot; targetNamespace=&quot;http://services.memorynotfound.com/&quot; elementFormDefault=&quot;qualified&quot;&gt;
&lt;xs:complexType name=&quot;CourseRequest&quot;&gt;
&lt;xs:sequence&gt;
&lt;xs:element name=&quot;id&quot; type=&quot;xs:int&quot; nillable=&quot;false&quot;/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;xs:complexType name=&quot;CourseResponse&quot;&gt;
&lt;xs:sequence&gt;
&lt;xs:element name=&quot;id&quot; type=&quot;xs:int&quot;/&gt;
&lt;xs:element name=&quot;name&quot; type=&quot;xs:string&quot;/&gt;
&lt;xs:element name=&quot;description&quot; type=&quot;xs:string&quot;/&gt;
&lt;xs:element name=&quot;created&quot; type=&quot;xs:dateTime&quot;/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;/xs:schema&gt;

huangapple
  • 本文由 发表于 2020年10月1日 19:25:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/64154425.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定