Maven Xjc / Jaxb插件无法解析简单的Xsd文件

问题描述 投票:0回答:1

我正在使用org.jvnet插件并尝试将xsd文件转换为Java Jaxb注释对象,以用于编组和解组。但是,在尝试编译简单的Xsd文件以供使用时出错。

我认为我正在制作一个简单的语法错误,第二次看起来真的很感激。如果有更多细节我应该提供,请告诉我。所有相关文件和消息都包含在下面。

错误信息:

[ERROR] Error while parsing schema(s).Location [ file:/C:/.../project/asdfasdf/src/main/resources/RandomObjectSchema.
xsd{6,46}].

org.xml.sax.SAXParseException; systemId:
  file:/C:/.../project/asdfasdf/src/main/resources/RandomObjectSchema.xsd;
    lineNumber: 6; columnNumber: 46; src-resolve.4.2: Error resolving component 'xsd:int'.
    It was detected that 'xsd:int' is in namespace 'http://www.w3c.org/2001/XMLSchema',
    but components from this namespace are not referenceable from schema document
    'file:/C:/.../project/asdfasdf/src/main/resources/RandomObjectSchema.xsd'.
    If this is the incorrect namespace, perhaps the prefix of 'xsd:int' needs to be changed.
    If this is the correct namespace, then an appropriate 'import' tag should be added to 
    'file:/C:/.../project/asdfasdf/src/main/resources/RandomObjectSchema.xsd'.




        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAX
ParseException(ErrorHandlerWrapper.java:203)
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Err
orHandlerWrapper.java:134)

File.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3c.org/2001/XMLSchema" targetNamespace="http://asdf.com/asdf">
    <xsd:element name="RandomObject">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="value" type="xsd:int"></xsd:element>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

Pom.hml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>asdf</groupId>
  <artifactId>asdfasdf</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>asdfasdf</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.13.1</version>
            <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
        </plugin>
    </plugins>
  </build>

</project>
xsd jaxb xjc
1个回答
2
投票

您的xsd命名空间中有错误。

你有:

http://www.w3c.org/2001/XMLSchema

它应该是:

http://www.w3.org/2001/XMLSchema

www.w3c.org对阵www.w3.org

错误日志非常详细:

[ERROR] s4s-elt-schema-ns: The namespace of element 'schema' must be from the schema namespace, 'http://www.w3.org/2001/XMLSchema'.
  line 2 of file:/.../test.xsd
© www.soinside.com 2019 - 2024. All rights reserved.