2

maven-jaxb2-plugin を使用しています。これが私のプラグイン構成です

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <executions>
        <execution>
            <id>xjc-serviceoperations</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <generateDirectory>${basedir}/src/main/java/</generateDirectory>
                <schemaDirectory>src/main/resources/schemas/lmsapi/serviceoperations</schemaDirectory>
                <removeOldOutput>false</removeOldOutput>
            </configuration>
        </execution>
        <execution>
            <id>xjc-types</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <generateDirectory>${basedir}/src/main/java</generateDirectory>
                <schemaDirectory>src/main/resources/schemas/lmsapi/types</schemaDirectory>
                <bindingDirectory>src/main/resources/schemas</bindingDirectory>
                <bindingIncludes>
                    <include>schema-binding.xjb</include>
                </bindingIncludes>
                <removeOldOutput>false</removeOldOutput>
            </configuration>
        </execution>
    </executions>
</plugin>   

ここに私のschema-binding.xmlファイルがあります

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:annox="http://annox.dev.java.net"
    xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb 
                    http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
    version="2.1">

    <jaxb:globalBindings>
        <jaxb:javaType name="java.time.LocalDateTime" xmlType="xsd:dateTime"
            parseMethod="com.softech.ls360.lms.api.proxy.xsd.binder.XSDateTimeCustomBinder.parseDateTime"
            printMethod="com.softech.ls360.lms.api.proxy.xsd.binder.XSDateTimeCustomBinder.printDateTime" />

    <jaxb:javaType name="java.time.LocalDate" xmlType="xsd:date"
            parseMethod="com.softech.ls360.lms.api.proxy.xsd.binder.XSDateCustomBinder.parseDateTime"
            printMethod="com.softech.ls360.lms.api.proxy.xsd.binder.XSDateCustomBinder.printDateTime" />

        <xjc:serializable uid="1" /> 
    </jaxb:globalBindings>

</jaxb:bindings>

私は xsd を持っていEnrollments.xsdます。私は日付型を持っています。date または datetime 型の xsd は、XMLGregorianCalendar ではなく Localdate または Localdatetime に変換する必要があります。ここにスニペットがあります

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://enrollment.types.lmsapi.message.webservice.lms.vu360.softech.com"
    xmlns="http://enrollment.types.lmsapi.message.webservice.lms.vu360.softech.com" 
    elementFormDefault="qualified"
    attributeFormDefault="unqualified">

    <xsd:include schemaLocation="Learner.xsd"/>
    ...
    <xsd:complexType name="LearnerEnrollCourses">  
        <xsd:sequence>  
            <xsd:element name="CourseId" type="xsd:string" minOccurs="1" maxOccurs="unbounded" nillable="false"  />
        </xsd:sequence> 
        <xsd:attribute name="enrollmentStartDate" type="xsd:date" use="required" />
         <xsd:attribute name="enrollmentEndDate" type="xsd:date" use="required" /> 
    </xsd:complexType>
    ...
</xsd:schema>

ここで、POM を右クリックします。を選択するRun As -> Maven generate-sourcesと、次のエラーが表示されます

[INFO] Sources are not up-to-date, XJC will be executed.
[ERROR] Error while parsing schema(s).Location [ file:/D:/Basit/eclipse-jee-mars-2/workspace/360Training/Java%208/LS360ProxyAPI/LmsApiProxy/src/main/resources/schemas/schema-binding.xjb{12,26}].
com.sun.istack.SAXParseException2; systemId: file:/D:/Basit/eclipse-jee-mars-2/workspace/360Training/Java%208/LS360ProxyAPI/LmsApiProxy/src/main/resources/schemas/schema-binding.xjb; lineNumber: 12; columnNumber: 26; only one globalBindings customization is allowed in a whole compilation
at com.sun.tools.xjc.ErrorReceiver.error(ErrorReceiver.java:86)
at com.sun.tools.xjc.reader.xmlschema.ErrorReporter.error(ErrorReporter.java:84)
....
[ERROR] Error while parsing schema(s).Location [ file:/D:/Basit/eclipse-jee-mars-2/workspace/360Training/Java%208/LS360ProxyAPI/LmsApiProxy/src/main/resources/schemas/schema-binding.xjb{12,26}].
com.sun.istack.SAXParseException2; systemId: file:/D:/Basit/eclipse-jee-mars-2/workspace/360Training/Java%208/LS360ProxyAPI/LmsApiProxy/src/main/resources/schemas/schema-binding.xjb; lineNumber: 12; columnNumber: 26; (related to above) but one is already given at this location

クラスは生成されていますが。ただし、型は依然として XMLGregorianCalendar です。

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "LearnerEnrollCourses", propOrder = {
    "courseId"
})
public class LearnerEnrollCourses {

    @XmlElement(name = "CourseId", required = true)
    protected List<String> courseId;

    @XmlAttribute(name = "enrollmentStartDate", required = true)
    @XmlSchemaType(name = "date")
    protected XMLGregorianCalendar enrollmentStartDate;

    @XmlAttribute(name = "enrollmentEndDate", required = true)
    @XmlSchemaType(name = "date")
    protected XMLGregorianCalendar enrollmentEndDate;

構成で何が間違っているのか、どうすれば解決できますか?

ありがとう

- - - - - - - - - - -編集 - - - - - - - - - - - -

このプラグイン構成は機能しています。

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <executions>
        <execution>
            <id>xjc-serviceoperations</id>
            <phase>generate-resources</phase>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <generateDirectory>${basedir}/src/main/java/</generateDirectory>
                <schemaIncludes>
                    <schemaInclude>schemas/lmsapi/serviceoperations/*.xsd</schemaInclude>
                </schemaIncludes>
                <bindingIncludes>
                    <bindingInclude>schemas/schema-binding.xjb</bindingInclude>
                </bindingIncludes>
                <verbose>true</verbose>
                <extension>true</extension>
                <removeOldOutput>false</removeOldOutput>
            </configuration>
        </execution>
        <execution>
            <id>xjc-types</id>
            <phase>generate-resources</phase>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <generateDirectory>${basedir}/src/main/java</generateDirectory>
                <schemaDirectory>schemas/lmsapi/types</schemaDirectory>
                <schemaIncludes>
                    <schemaInclude>**/*.xsd</schemaInclude>
                </schemaIncludes>
                <schemaExcludes>
                    <schemaExclude>Enrollment.xsd</schemaExclude>
                </schemaExcludes>
                <removeOldOutput>false</removeOldOutput>
                <verbose>true</verbose>
                <extension>true</extension>
            </configuration>
        </execution>
    </executions>
</plugin>

ここに私のschema-binding.xjbがあります

<jaxb:globalBindings>

    <jaxb:javaType name="java.time.LocalDateTime" xmlType="xsd:dateTime"
            parseMethod="com.softech.ls360.lms.api.proxy.schema.binder.XSDateTimeCustomBinder.parseDateTime"
            printMethod="com.softech.ls360.lms.api.proxy.schema.binder.XSDateTimeCustomBinder.printDateTime" />

    <jaxb:javaType name="java.time.LocalDate" xmlType="xsd:date"
            parseMethod="com.softech.ls360.lms.api.proxy.schema.binder.XSDateCustomBinder.parseDateTime"
            printMethod="com.softech.ls360.lms.api.proxy.schema.binder.XSDateCustomBinder.printDateTime" />

    <!-- Force all classes implements Serializable -->
    <xjc:serializable uid="1" />

</jaxb:globalBindings>


<jaxb:bindings schemaLocation="lmsapi/types/Enrollment.xsd" node="/xsd:schema" >
    <jaxb:schemaBindings >
        <jaxb:package name="com.softech.vu360.lms.webservice.message.lmsapi.types.enrollment" />
    </jaxb:schemaBindings>
</jaxb:bindings>

これは、serviceoperations および types ディレクトリのファイルの 1 つです。

EnrollmentServiceOperations.xsd:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://enrollment.serviceoperations.lmsapi.message.webservice.lms.vu360.softech.com"
    xmlns="http://enrollment.serviceoperations.lmsapi.message.webservice.lms.vu360.softech.com"
    xmlns:enrolmnt="http://enrollment.types.lmsapi.message.webservice.lms.vu360.softech.com"
    xmlns:tr="http://transactionresult.types.lmsapi.message.webservice.lms.vu360.softech.com"
    elementFormDefault="qualified" attributeFormDefault="unqualified">

    <xsd:import namespace="http://transactionresult.types.lmsapi.message.webservice.lms.vu360.softech.com" schemaLocation="../types/TransactionResultType.xsd"/>
    <xsd:import namespace="http://enrollment.types.lmsapi.message.webservice.lms.vu360.softech.com" schemaLocation="../types/Enrollment.xsd"/>

    <xsd:element name="LearnerCoursesEnrollRequest">
        <xsd:complexType>
            ....
        </xsd:complexType>
    </xsd:element>
    ....
</xsd:schema>

CustomerServiceOperations.xsd:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://customer.serviceoperations.lmsapi.message.webservice.lms.vu360.softech.com"
    xmlns="http://customer.serviceoperations.lmsapi.message.webservice.lms.vu360.softech.com"
    xmlns:cust="http://customer.types.lmsapi.message.webservice.lms.vu360.softech.com"
    xmlns:tr="http://transactionresult.types.lmsapi.message.webservice.lms.vu360.softech.com"
    elementFormDefault="qualified" attributeFormDefault="unqualified">

    <xsd:import namespace="http://transactionresult.types.lmsapi.message.webservice.lms.vu360.softech.com" schemaLocation="../types/TransactionResultType.xsd"/>
    <xsd:import namespace="http://customer.types.lmsapi.message.webservice.lms.vu360.softech.com" schemaLocation="../types/Customer.xsd"/>

    <xsd:element name="AddCustomerRequest">
        <xsd:complexType>
            ...
        </xsd:complexType>
    </xsd:element>
    ...
</xsd:schema>

タイプ/登録.xsd

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://enrollment.types.lmsapi.message.webservice.lms.vu360.softech.com"
    xmlns="http://enrollment.types.lmsapi.message.webservice.lms.vu360.softech.com" 
    elementFormDefault="qualified"
    attributeFormDefault="unqualified">

    <xsd:include schemaLocation="Learner.xsd"/>

    <xsd:complexType name="LearnerCourses">  
        ....  
    </xsd:complexType>
    ....
</xsd:schema>

タイプ/Customer.xsd

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://customer.types.lmsapi.message.webservice.lms.vu360.softech.com"
    xmlns="http://customer.types.lmsapi.message.webservice.lms.vu360.softech.com" 
    xmlns:addr="http://address.types.lmsapi.message.webservice.lms.vu360.softech.com"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified">

    <xsd:import namespace="http://address.types.lmsapi.message.webservice.lms.vu360.softech.com" schemaLocation="Address.xsd"/>

    <xsd:complexType name="Customers">  
        <xsd:sequence>  
            ....
        </xsd:sequence>  
    </xsd:complexType>
    ...
</xsd:schema>

今私が走るときRun As -> Maven generate-sources。で serviceoperations ソースを生成しsrc/main/java/com/..../serviceoperation/customer/AddCustomerRequest.java、 でタイプ ソースを生成しsrc/main/java/com/.../types/customer/Customers.javaます。他の xsds についても同様です。

を使用してはならないのはなぜですか<generateDirectory>${basedir}/src/main/java/</generateDirectory>。これが私が欲しいものです。このプラグインは、各 xsd の targetnamespace からパッケージを作成していると思います。私は正しいですか?

このプラグインの構成で何か間違ったことをしている場合は、修正できるように教えてください。あなたがsrc/main/javaで生成しないと言ったように。

serviceoperations フォルダー内のすべての xsds が、フォルダー内に(src/main/resources/schemas/lmsapi/serviceoperation/*.xsd)生成されsrc/main/java/com/..../serviceoperation/customer/*.java、他のsrc/main/java/com/..../serviceoperation/enrollment/*.javaフォルダーと同じように生成されるようにします。

内のすべての xsds は、フォルダ内に(src/main/resources/schemas/lmsapi/types/*.xsd)生成され、他のものについても同じである必要があります。src/main/java/com/..../types/customer/*.javasrc/main/java/com/..../types/enrollment/*.java

また、バインディング ファイルは(src/main/resources/schemas/schema-binding.xjb)、servieoperations および types フォルダー内のすべての xsds に適用されます。

このプラグインを構成するためのより良い方法はありますか?教えてください。自分で修正できます。あなたがこのプラグインの作者だと思います。

ありがとうございます。それでは、お元気で

バシット・マフムード・アーメド

4

2 に答える 2