我可以使用 Eclipse 轻松地将 JavaDoc 添加到包中吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/893474/
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-09-10 18:44:03  来源:igfitidea点击:

Can I add JavaDoc to a package easily with Eclipse?

eclipsejavadoc

提问by Hanno Fietz

I use javadoc to document my classes and methods. I would like to add some overview information to my packages, too. I like how Eclipse creates a stub of a matching Doc Comment for each class or method once I type /**<Enter>. Does Eclipse have an easy way to generate a package.html file, too?

我使用 javadoc 来记录我的类和方法。我也想在我的包中添加一些概述信息。我喜欢 Eclipse 如何在我键入后为每个类或方法创建一个匹配的 Doc Comment 存根/**<Enter>。Eclipse 是否也有生成package.html 文件的简单方法?

回答by VonC

Update 4 years later (Oct. 2013)

4 年后更新(2013 年 10 月)

javabeangrinder's answer(upvoted) mentions the following trick:

javabeangrinder回答(已投票)提到了以下技巧:

To create a package-info.javafile in an existing package:

package-info.java在现有包中创建文件:

  • Right click on the package where you want a package-info.java.
  • Select new->package.
  • Check the Create package.info.javacheck box.
  • Click on Finish
  • 右键单击您想要package-info.java.
  • 选择new->package
  • 选中Create package.info.java复选框。
  • 点击 Finish


Original answer (May 2009)

原始答案(2009 年 5 月)

There is no template or wizard to easily create a package.html file.

没有模板或向导可以轻松创建 package.html 文件。

As mmyerssaid in his comment, since Java1.5, the correct file to create would be package-info.java.
That file can be used not only for javadocs, but also for package-level annotations(as illustrated here).

正如mmyers在他的评论中所说,因为Java1.5,要创建的正确文件将是package-info.java.
该文件不仅可以用于 javadoc,还可以用于包级注释(如图所示)。

There is an opened Bug (#86168)for demanding a wizard for the creation of package-info.java(since the class wizard does not allow the package-infoname).

有一个已打开的 Bug (#86168)要求创建一个向导package-info.java(因为类向导不允许使用package-info名称)。

The reflections on that topic are on since... 2005! The problem is that any solution should be implemented in a way that it also helps with 1.4code.

关于该主题的思考自... 2005 年以来!问题在于,任何解决方案都应该以对1.4代码也有帮助的方式实现。

The current workaround is to create a package-info.javaas a textfile.
From that point forward, package-info.javabehaves as a normal Java class, and Eclipse places a package-info.classfile in the output folder.
The Javadocsare correctly built using package-info.java, and not the package.htmlfile.

当前的解决方法是创建package-info.java一个text文件。
从那时起,它的package-info.java行为就像一个普通的 Java 类,Eclipsepackage-info.class在输出文件夹中放置一个文件。
Javadocs使用正确构建package-info.java,而不是package.html文件。

alt text
(source: developpez.com)

替代文字
(来源:developpez.com



Note (in response to Strawberry's comment):

注意(响应Strawberry的评论):

both wisha preview of the package overview in package-info.java in the Javadoc view.

希望一个包概述的预览中的Javadoc视图package-info.java

So far, no patch has been proposed/implemented.
There is simply not enough demands for that feature to be added.

到目前为止,还没有提出/实施补丁。
根本没有足够的需求来添加该功能。

回答by javabeangrinder

In eclipse

在日食

Since package-info.java isn't a valid identifier for a class it cannot be created as a class in Eclipse.

由于 package-info.java 不是类的有效标识符,因此无法在 Eclipse 中将其创建为类。

I found that when you create a new package there is a check box to check if you want a package-info.java.

我发现当你创建一个新的包时,有一个复选框来检查你是否想要一个 package-info.java。

To create a package-info.java file in an existing package:

在现有包中创建 package-info.java 文件:

  1. Right click on the package where you want a package-info.java.
  2. Select new->package.
  3. Check the Create package.info.java check box.
  4. Click on Finish
  1. 右键单击您想要 package-info.java 的包。
  2. 选择新建-> 包。
  3. 选中创建 package.info.java 复选框。
  4. 点击完成

回答by NathanChristie

The JAutodocplugin does a great job of this, as well as all your other documentation needs. Install and configure the plugin and right click the package and click JAutodoc > Add Package Javadoc

JAutodoc插件做的这一个伟大的工作,以及所有其他文档的需求。安装并配置插件并右键单击包并单击JAutodoc > 添加包 Javadoc

There are configurations and templates available for the .javaor .htmlpackage documentation.

.java.html包文档有可用的配置和模板。

This plugin also does a great job of standardizing all your Javadoc needs, with a great deal of customization.

这个插件在标准化你所有的 Javadoc 需求方面也做得很好,有大量的定制。

http://jautodoc.sourceforge.net/

http://jautodoc.sourceforge.net/

回答by gMale

There's a plugin that seems to create package.html files. I haven't used it but someone landing here might find it useful.

有一个插件似乎可以创建 package.html 文件。我没有用过它,但登陆这里的人可能会发现它很有用。

http://sourceforge.net/projects/package-javadoc/

http://sourceforge.net/projects/package-javadoc/