为什么我的构建失败了jax-ws maven插件?

时间:2015-11-18 11:06:15

标签: java xml web-services maven

我是Web服务的新手,因此我正在构建一个可以在本地部署到Tomcat的Hello World类型程序。但是,在尝试根据我的XML架构生成域类时,我目前遇到了问题。

我的XSD架构如下:

    <?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.example.org/helloworld" xmlns:tns="http://www.example.org/helloworld"
    elementFormDefault="qualified">

    <xs:element name="request" type="tns:requestType">
    </xs:element>
    <xs:complexType name="requestType">
        <xs:sequence>
            <xs:element name="name" type="xs:string" />
            <xs:element name="message" type="xs:string" />
        </xs:sequence>
    </xs:complexType>


    <xs:element name="response" type="tns:responseType">
    </xs:element>
    <xs:complexType name="responseType">
        <xs:sequence>
            <xs:element name="message" type="xs:string" />
        </xs:sequence>
    </xs:complexType>


</schema>

我的pom.xml中的jax-ws插件配置如下:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jaxb2-maven-plugin</artifactId>
        <version>1.6</version>
        <executions>
            <execution>
                <goals>
                    <goal>xjc</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <schemaDirectory>src/main/resources</schemaDirectory>
            <schemaIncludes>
                <include>xsd/*.xsd</include>
                <include>schema/*/*.xsd</include>
            </schemaIncludes>
        </configuration>
    </plugin>

但是,我目前遇到以下构建错误:

[INFO] Failed to parse a schema.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.947s
[INFO] Finished at: Wed Nov 18 11:04:37 GMT 2015
[INFO] Final Memory: 8M/20M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:1.6:xjc (default) on project hello-world: Could not process schema files in directory D:\Home\Workspaces\webservice\hello-world\src\main\resources -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

1 个答案:

答案 0 :(得分:1)

您正在使用未在架构中定义的xs。 xmlns:xs =“http://www.w3.org/2001/XMLSchema”缺失 尝试替换:

<schema xmlns="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.example.org/helloworld" xmlns:tns="http://www.example.org/helloworld"
    elementFormDefault="qualified">

使用:

<schema xmlns="http://www.w3.org/2001/XMLSchema"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.example.org/helloworld" xmlns:tns="http://www.example.org/helloworld"
    elementFormDefault="qualified">