У меня есть разные файлы .xsd, и я хочу создать из них классы Java в разных пакетах. Я настраиваю maven maven-jaxb2-plugin
следующим образом
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.11.0</version>
<executions>
<execution>
<id>generate-messages</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<forceRegenerate>true</forceRegenerate>
<generateDirectory>${basedir}/src/main/java</generateDirectory>
<schemas>
<schema>
<fileset>
<directory>${basedir}/src/main/resources/bindings</directory>
<includes>
<include>lmsApiBinding.xml</include>
</includes>
</fileset>
</schema>
</schemas>
</configuration>
</plugin>
Вот мой файл
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
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 generateElementProperty="false">
<xjc:serializable uid="1" />
</jaxb:globalBindings>
<jaxb:bindings schemaLocation="/src/main/webapp/schemas/lmsapi/serviceoperations/CustomerServiceOperations.xsd" node="/xsd:schema">
<jaxb:schemaBindings>
<jaxb:package name="abc.customer" />
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="/src/main/webapp/schemas/lmsapi/serviceoperations/EnrollmentServiceOperations.xsd" node="/xsd:schema">
<jaxb:schemaBindings>
<jaxb:package name="def.enrollment" />
</jaxb:schemaBindings>
</jaxb:bindings>
....
</jaxb:bindings>
Вот мой 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:sequence>
<xsd:element name="Customers" type="cust:Customers" minOccurs="1" maxOccurs="1" nillable="false" />
</xsd:sequence>
<xsd:attribute name="key" type="xsd:string" use="required" />
<xsd:attribute name="ResellerId" type="xsd:nonNegativeInteger" use="required" />
</xsd:complexType>
</xsd:element>
<xsd:element name="AddCustomerResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="RegisterCustomers" type="cust:RegisterCustomers" minOccurs="0" maxOccurs="1" nillable="false" />
</xsd:sequence>
<xsd:attribute name="transactionResult" type="tr:TransactionResultType" use="required"/>
<xsd:attribute name="transactionResultMessage" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Но когда я нажимаю на свой файл .pom
и выбираю Run As --> maven Generate Sources
, я получаю следующие ошибки
org.xml.sax.SAXParseException; systemId: file:/D:/Basit/eclipse-jee-luna/workspace/lms-api-1/src/main/resources/bindings/lmsApiBinding.xml; lineNumber: 10; columnNumber: 19; s4s-elt-schema-ns: The namespace of element 'bindings' must be from the schema namespace, 'http://www.w3.org/2001/XMLSchema'.
...
org.xml.sax.SAXParseException; systemId: file:/D:/Basit/eclipse-jee-luna/workspace/lms-api-1/src/main/resources/bindings/lmsApiBinding.xml; lineNumber: 10; columnNumber: 19; s4s-elt-invalid: Element 'bindings' is not a valid element in a schema document.
...
org.xml.sax.SAXParseException; systemId: file:/D:/Basit/eclipse-jee-luna/workspace/lms-api-1/src/main/resources/bindings/lmsApiBinding.xml; lineNumber: 10; columnNumber: 19; schema_reference.4: Failed to read schema document 'file:/D:/Basit/eclipse-jee-luna/workspace/lms-api-1/src/main/resources/bindings/lmsApiBinding.xml', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
Почему я получаю эти ошибки? Что я делаю неправильно?
Спасибо
------ Изменить----
<schemas>
<schema>
<fileset>
<directory>${basedir}/src/main/webapp/schemas/lmsapi</directory>
<includes>
<include>/serviceoperations/CustomerServiceOperations.xsd</include>
<include>/serviceoperations/EnrollmentServiceOperations.xsd</include>
<include>/serviceoperations/OrgGroupServiceOperations.xsd</include>
...
<include>/types/Address.xsd</include>
<include>/types/Course.xsd</include>
<include>/types/Customer.xsd</include>
....
<include>/types/UserGroup.xsd</include>
<include>/types/Vu360User.xsd</include>
</includes>
</fileset>
</schema>
</schemas>
--Окончательный рабочий код--
Привет спасибо. Наконец заработало. Вот мой файл LmsApiServiceOperations.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://com/softech/vu360/lms/webservice/message/lmsapi/serviceoperations"
xmlns="http://com/softech/vu360/lms/webservice/message/lmsapi/serviceoperations"
elementFormDefault="qualified">
<xsd:import namespace="http://trainingplan.serviceoperations.lmsapi.message.webservice.lms.vu360.softech.com" schemaLocation="TrainingPlanServiceOperations.xsd"/>
<xsd:import namespace="http://customer.serviceoperations.lmsapi.message.webservice.lms.vu360.softech.com" schemaLocation="CustomerServiceOperations.xsd"/>
<xsd:import namespace="http://user.serviceoperations.lmsapi.message.webservice.lms.vu360.softech.com" schemaLocation="UserServiceOperations.xsd"/>
<xsd:import namespace="http://enrollment.serviceoperations.lmsapi.message.webservice.lms.vu360.softech.com" schemaLocation="EnrollmentServiceOperations.xsd"/>
<xsd:import namespace="http://securityroles.serviceoperations.lmsapi.message.webservice.lms.vu360.softech.com" schemaLocation="SecurityRoleServiceOperations.xsd"/>
<xsd:import namespace="http://orggroup.serviceoperations.lmsapi.message.webservice.lms.vu360.softech.com" schemaLocation="OrgGroupServiceOperations.xsd"/>
<xsd:import namespace="http://usergroup.serviceoperations.lmsapi.message.webservice.lms.vu360.softech.com" schemaLocation="UserGroupServiceOperations.xsd"/>
</xsd:schema>
Вот конфигурация плагина
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.11.0</version>
<executions>
<execution>
<id>generate-messages</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<bindingDirectory>${basedir}/src/main/resources/bindings</bindingDirectory>
<bindingIncludes>
<bindingInclude>lmsApiBinding.xml</bindingInclude>
</bindingIncludes>
<generateDirectory>${basedir}/src/main/java/</generateDirectory>
<schemas>
<schema>
<fileset>
<directory>${basedir}/src/main/webapp/schemas/lmsapi/</directory>
<includes>
<include>serviceoperations/LmsApiServiceOperations.xsd</include>
</includes>
</fileset>
</schema>
</schemas>
<strict>true</strict>
<extension>true</extension>
<verbose>true</verbose>
<forceRegenerate>true</forceRegenerate>
</configuration>
</execution>
</executions>
</plugin>
Также мой файл lmsApiBinding.xml теперь содержит только
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
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 generateElementProperty="false">
<xjc:serializable uid="1" />
</jaxb:globalBindings>
</jaxb:bindings>
Потому что, если я использую что-то вроде
<jaxb:globalBindings generateElementProperty="false">
<xjc:serializable uid="1" />
</jaxb:globalBindings>
<jaxb:bindings schemaLocation="CustomerServiceOperations.xsd" node="/xsd:schema">
<jaxb:schemaBindings>
<jaxb:package name="com.softech.vu360.lms.webservice.message.lmsapi.serviceoperations.customer" />
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="/schemas/lmsapi/serviceoperations/EnrollmentServiceOperations.xsd" node="/xsd:schema">
<jaxb:schemaBindings>
<jaxb:package name="com.softech.vu360.lms.webservice.message.lmsapi.serviceoperations.enrollment" />
</jaxb:schemaBindings>
</jaxb:bindings>
Затем выберите Maven --> Создать источники. Затем я получаю следующую ошибку
com.sun.istack.SAXParseException2; systemId: file:/D:/Basit/eclipse-jee-luna/workspace/360Training/lms-api-1/src/main/resources/bindings/lmsApiBinding.xml; lineNumber: 17; columnNumber: 86; "file:/D:/Basit/eclipse-jee-luna/workspace/360Training/lms-api-1/src/main/resources/bindings/CustomerServiceOperations.xsd" is not a part of this compilation. Is this a mistake for "file:/D:/Basit/eclipse-jee-luna/workspace/360Training/lms-api-1/src/main/resources/bindings/lmsApiBinding.xml"?
Я использовал файл привязки, потому что хочу создавать классы в разных пакетах. Но кажется, что он генерирует имя пакета из целевого пространства имен. Как я заявил в своем файле 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:schema>
Итак, после генерации sources. Он автоматически поместил мои CustomerServiceOperations.xsd
операции в пакет com.softech.vu360.lms.webservice.message.lmsapi.serviceoperations.customer
Спасибо
<include>serviceoperations/*.xsd</include>
. - person lexicore   schedule 08.12.2014