JDK8与JDK8(WS客户端)不兼容。

7
我有一个非常简单(已存在的)Web服务,我希望使用JDK8生成Web服务客户端。
我使用纯JDK8工具链,这意味着我使用来自我的JDK8目录的wsimport工具。
现在问题来了:JDK8中wsimport工具生成的Java源代码不符合JDK8 Javadoc规范。正如您所知,Javadoc工具在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;
    }

}

问题出在这个类的生成注释上。虽然这种类型的注释在JDK7中可以被Javadoc编译器接受,但在JDK8中不再适用(必须将结尾的 > 替换为 &gt; 才能在JDK8中正确)。这些无效注释的结果是构建失败。
我知道我可以 关闭JDK8中的doclint,但我想知道我是否做错了什么。这只是纯粹的JDK8工具。没有什么花哨的东西。这些工具应该可以一起使用,对吧?并且在被Oracle发布之前已经进行了彻底的测试?所以我认为我做错了什么。比如说什么?
谢谢。
重现步骤: 链接到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工具也会产生许多警告。我可以接受这一点。但是错误会导致构建失败。
1个回答

2

我只能确认你的发现。由于复制这个问题所需的设置很少,没有松散的端口,因此目前唯一合理的结论是,这是OpenJDK 8中打包的wsimport工具中的一个错误。该工具仅未更新以反映同一JDK软件包的javadoc工具施加的新限制。


既然你花时间复制了这个,我会把你的答案作为正确答案接受...尽管我和你一样惊讶...当然,这并不是我要找的答案。 :-) - peterh
由于这个答案并没有真正帮助你找到解决方案,我已将其发布为社区维基。它可以作为一个占位符,在这个问题上其他人可以贡献任何进一步的发展。 - Marko Topolnik
是的。我也更新了恐怖故事列表,这意味着由于JDK8中新的更严格的Javadoc而现在已经损坏的东西。(除了这种情况之外还有其他情况,尽管它们不是bug) - peterh

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接