【问题标题】:JDK8 not working with JDK8 (WS client)JDK8 不适用于 JDK8(WS 客户端)
【发布时间】:2014-08-21 03:31:01
【问题描述】:

我有一个非常简单的(现有)Web 服务,我想生成一个针对使用 JDK8 的 Web 服务客户端。

我使用的是纯 JDK8 工具链,这意味着我使用 JDK8 目录中的 wsimport 工具。

现在问题来了:JDK8 中 wsimport 工具生成的 Java 源代码不符合 JDK8 Javadoc。如您所知,Javadoc 工具已变为 a lot more strict in JDK8

考虑以下简单架构:

<xs:schema version="1.0" targetNamespace="http://mavenwsserver.ws.mytest.org/">
  <xs:element name="operation" type="tns:operation"/>
  <xs:element name="operationResponse" type="tns:operationResponse"/>
  <xs:complexType name="operation">
    <xs:sequence>
      <xs:element name="person" type="tns:person" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="person">
    <xs:sequence>
      <xs:element name="firstName" type="xs:string" minOccurs="0"/>
      <xs:element name="lastName" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="operationResponse">
    <xs:sequence>
      <xs:element name="return" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

为此,wsimport 工具将生成如下 Java 代码:

package org.mytest.ws.mavenwsclient;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;


/**
 * <p>Java class for person complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType name="person">
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element name="firstName" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
 *         &lt;element name="lastName" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "person", propOrder = {
    "firstName",
    "lastName"
})
public class Person {

    protected String firstName;
    protected String lastName;

    /**
     * Gets the value of the firstName property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getFirstName() {
        return firstName;
    }

    /**
     * Sets the value of the firstName property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setFirstName(String value) {
        this.firstName = value;
    }

    /**
     * Gets the value of the lastName property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getLastName() {
        return lastName;
    }

    /**
     * Sets the value of the lastName property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setLastName(String value) {
        this.lastName = value;
    }

}

问题是为此类生成的 cmets。虽然 JDK7 中的 Javadoc 编译器会接受这种类型的 cmets,但它在 JDK8 中不再适用。 (结尾 > 必须替换为 &amp;gt; 以使其在 JDK8 中正确)。这些无效的 cmets 的结果是构建失败。

我知道我可以turn off doclint in JDK8 但我想知道我在这里做错了什么。它只是纯粹的 JDK8 工具。没有什么花哨。这些工具应该一起工作吧?并在被 Oracle 发布之前经过了彻底的测试?所以我假设我做错了什么。比如什么?

谢谢。

复制步骤

Link to WSDL(包括架构)

将此文件下载到硬盘上的某个位置。

我使用这样的wsimport 命令行:

mkdir D:\JavaDevHG\MavenWSClient\target\generated-sources\jaxws-wsimport

"C:\Program Files\Java\jdk1.8.0_05\bin\wsimport" -keep ^
  -s D:\JavaDevHG\MavenWSClient\target\generated-sources\jaxws-wsimport ^
  D:/JavaDevHG/MavenWSClient/src/main/wsdl/myWSDL.xml

现在在生成的源上运行javadoc

"C:\Program Files\Java\jdk1.8.0_05\bin\javadoc" ^
   -sourcepath D:\JavaDevHG\MavenWSClient\target\generated-sources\jaxws-wsimport ^
   -subpackages org

你会看到这样的东西:

Loading source files for package org.mytest.ws.mavenwsserver...
Constructing Javadoc information...
Standard Doclet version 1.8.0_05
Building tree for all the packages and classes...
Generating .\org\mytest\ws\mavenwsserver\HelloWorldWebService.html...
...
...
Generating .\org\mytest\ws\mavenwsserver\Person.html...
..\..\..\target\generated-sources\jaxws-wsimport\org\mytest\ws\mavenwsserver\Person.java:15: error: bad use of '>'
 * &lt;complexType name="person">
                                ^
..\..\..\target\generated-sources\jaxws-wsimport\org\mytest\ws\mavenwsserver\Person.java:16: error: bad use of '>'
 *   &lt;complexContent>
...
...                       ^

请注意,Javadoc 工具也会产生一堆警告。我可以忍受这一点。导致构建失败的是错误。

【问题讨论】:

    标签: java web-services java-8 wsimport


    【解决方案1】:

    我只能确认您的发现。由于重现此问题所需的设置很少,没有松散的结局,因此到目前为止唯一合理的结论是这是与 OpenJDK 8 一起打包的 wsimport 工具中的一个错误。这个工具根本没有更新以反映新的同一JDK包的javadoc工具所施加的限制。

    【讨论】:

    • 既然您愿意花时间重现此内容,我会接受您的答案是正确的……尽管我和您一样感到惊讶.. 当然不是真的是我一直在寻找的答案。 :-)
    • 由于此答案并不能真正帮助您解决问题,因此我已将其发布为社区 Wiki。它可以作为一个占位符,其他人可以在此问题上贡献任何进一步的发展。
    • 是的。我还更新了 list of horror stories,这意味着由于 JDK8 中新的更严格的 Javadoc 而导致的东西现在被破坏了。 (除此之外还有其他情况,虽然不是bug)
    猜你喜欢
    • 1970-01-01
    • 2014-05-25
    • 1970-01-01
    • 1970-01-01
    • 2016-06-29
    • 1970-01-01
    • 2020-04-06
    • 2016-10-15
    • 2018-03-26
    相关资源
    最近更新 更多