java JDK 8 中的 Javadoc:无效的“不允许自关闭元素”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26049329/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 09:12:35  来源:igfitidea点击:

Javadoc in JDK 8 : Invalid "self-closing element not allowed"

javamavenjavadoc

提问by JE42

What are the best workarounds when running javadoc using JDK 8 and one receives this error.

使用 JDK 8 运行 javadoc 并且收到此错误时,最好的解决方法是什么。

It seems that for JDK 8 it has been decided that tags like <br />and <p />should generate errors, because they are invalid (strict) HTML 4. see discussion JDK mailing list here

似乎对于 JDK 8 已经决定标签 like<br />并且<p />应该产生错误,因为它们是无效的(严格的)HTML 4。请参阅此处的讨论 JDK 邮件列表

I wonder, because I just wanted to compile some java project using maven and tripped over this issue. Of course, I can file a ticket with the project (and I guess I will), but it would be great if there is a way how to disable this behaviour (for a machine). Otherwise, I expect that a lot of projects need to be fixed before they can be built on JDK 8 without issues.

我想知道,因为我只是想使用 maven 编译一些 java 项目并被这个问题绊倒了。当然,我可以为项目提交一张票(我想我会),但如果有办法禁用此行为(对于机器),那就太好了。否则,我希望许多项目需要修复才能在 JDK 8 上构建而没有问题。

采纳答案by Tavo

For those two particular cases, I think the recommended action is to substitute them with <p>. Thisis the link to the Oracle documentation.

对于这两种特殊情况,我认为建议的操作是将它们替换为<p>. 是 Oracle 文档的链接。

回答by Xelian

To remove the errors in the javaDocsjust replace:

要删除javaDocs中的错误,只需替换:

  • <p/>with just <p>
  • <br/>with just <br>
  • <p/>只是 <p>
  • <br/>只是 <br>

Everything works fine after the correction in a excepted way.

以例外的方式更正后一切正常。

回答by Timmos

Taken from "What's New in JDK 8" from oracle.com:

摘自oracle.com 的“ JDK 8 中的新增功能”:

The javac tool now has support for checking the content of javadoc comments for issues that could lead to various problems, such as invalid HTML or accessibility issues, in the files that are generated when javadoc is run. The feature is enabled by the new -Xdoclint option. For more details, see the output from running "javac -X". This feature is also available in the javadoc tool, and is enabled there by default.

javac 工具现在支持检查 javadoc 注释的内容,以查找在运行 javadoc 时生成的文件中可能导致各种问题的问题,例如无效的 HTML 或可访问性问题。该功能由新的 -Xdoclint 选项启用。有关更多详细信息,请参阅运行“javac -X”的输出。此功能也可在 javadoc 工具中使用,默认情况下已启用。

Now I did what it told me to do. On JDK 7, the output of "javac -X" does not mention the -Xdoclint option. However, on JDK 8, it gives:

现在我做了它告诉我的事情。在 JDK 7 上,“javac -X”的输出没有提到 -Xdoclint 选项。但是,在 JDK 8 上,它提供:

 -Xdoclint:(all|none|[-]<group>)[/<access>]
    Enable or disable specific checks for problems in javadoc comments,
    where <group> is one of accessibility, html, missing, reference, or syntax,
    and <access> is one of public, protected, package, or private.

So, run the Javadoc utility as follows:

因此,按如下方式运行 Javadoc 实用程序:

javadoc.exe -Xdoclint:none <other options...>

In my script, the error you mentioned disappeared by using this option.

在我的脚本中,您提到的错误通过使用此选项消失了。

回答by Ralph Ritoch

While it is possible to disable error checking with the -Xdoclint option it doesn't repair the problem, it just hides the problem. To make valid HTML4 documents the following substitutions are correct.

虽然可以使用 -Xdoclint 选项禁用错误检查,但它不会修复问题,只是隐藏了问题。为了制作有效的 HTML4 文档,以下替换是正确的。

  • Replace self closing br tags with regular br tags (<br /> with <br>)
  • Replace empty p tags with br tags (<p /> with <br>)
  • Ensure all p tags have content and are closed (<p>... with <p> ...</p>)
  • 用常规 br 标签替换自关闭 br 标签(<br /> 与 <br>)
  • 用 br 标签替换空的 p 标签(<p /> 与 <br>)
  • 确保所有 p 标签都有内容并已关闭(<p>... with <p> ...</p>)