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

标签 java xml web-services maven

我是 Web 服务新手,因此目前正在构建一个 Hello World 类型的程序,我可以将其本地部署到 Tomcat。但是,我目前在尝试根据 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

最佳答案

您正在使用架构中未定义的 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">

关于java - 为什么我的 jax-ws maven 插件构建失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33778406/

相关文章:

java - 文本到语音 android 在 Activity 可见时输出语音

JavaFX FX :include scene visibility of parent controller

c# - 在 C# 中安全地解析 XML

android - LinearLayout透明度问题?

JavaEE : Web Service Deployed Successfully but Tester is not Working

Python - 通过身份验证将数据发送到 .NET Web 服务

java - 如何在后端解析 Seam URL?

java - 在Java中使用For循环打印2D字符数组

c# - 无需在客户端安装 mysql 连接器即可将应用程序转换为工作

java - 带有 MVC 的 Spring 3 JSON